Skip to content

baselrabia/go-book-app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Golang rest api 💻

Task 📝

  1. Create a simple Golang application that will serve a RESTful API with a resource (books). The endpoints should support Create, Read, Update and Delete operations.
  2. The data should be persisted in a database like SQLite, MySQL, PostgreSQL, etc.
  3. Add tests for you REST API.
  4. Create a dockerfile for your application.

Tips 🧞

Application example

Endpoints:

# Get all books
GET /books

# Get a specific book
GET /books/:id

# Create a book
POST /books

# Update a book
PUT /books/:id

# Delete a book
DELETE /books/:id

Model:

{
    "id": 1,
    "title": "The Alchemist",
    "author": "Paulo Coelho",
    "published": 1988
}

Database

This package can be used to connect to a local SQLite database:

If you want an ORM (Object Relational Mapping) library, you can use GORM:

REST API

For creating a HTTP server, you can use echo:

REST API testing

Documentation for testing echo endpoints:

to run test cases

go test -v

Repository Pattern

Repository pattern is a design pattern that we will use in our application. It's basically a way of encapsulating the data access layer logic In the context of Go and databases, it's common to use repositories in order to abstract away the underlying data source from your business logic.

Dockerization

For Create a dockerfile for your application

To build the docker image run this command in your terminal from root directory of project:

docker build -t go-restapi .

After building the image, you can start it with this command:

docker run --name restapi -d -p 8080:8080 go-restapi

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published