The project is a Book API written in Golang using libraries like Gin and GORM. This API performs all the CRUD operations like -
- Create a New Book with Title and Author.
- Retrieve all the Books that exist in the Database.
- Retrieve the Books with the given ID (automatically generated at creation).
- Retrieve the Book with the given Title.
- Retrieve all the Books with the given Author.
- Delete a Book with given ID.
- Update the Title or Author of a Book with given ID.
Gin is a web framework written in Go (Golang). It features a martini-like API with performance that is up to 40 times faster thanks to httprouter. For further information on the package, you can checkout - Gin Golang
GORM provides CRUD operations and can also be used for the initial migration and creation of the database schema.For further information on the package, you can checkout - GORM Golang
GET /books
GET /books/:id
Parameter | Type | Description |
---|---|---|
id |
uint |
Required. Id of item to fetch |
GET /books/title/:title
Parameter | Type | Description |
---|---|---|
title |
string |
Required. Id of item to fetch |
GET /books/author/:author
Parameter | Type | Description |
---|---|---|
author |
string |
Required. Id of item to fetch |
This operation here also prevents creation of duplicate data.
POST /books
- Request Body Example -
{
"title": "Fairy tales",
"author": "Hans Christian Andersen"
}
PATCH /books/:id
- Example 1
{
"title": "Fairy tales"
}
- Example 2
{
"author": "Stephenie Meyer"
}
- Example 3
{
"title": "Twilight"
"author": "Stephenie Meyer"
}
DELETE /books/:id
Parameter | Type | Description |
---|---|---|
id |
uint |
Required. Id of item to delete |
Developed dockerfile to build and run the bookapi service, Inorder to attach Database used MySql as a database and implemented docker-compose
- Git
- docker
- docker-compose
Clone repo to Local
git clone https://github.com/shashank-kakarla/BookAPI.git
Build & Deploy Book-API
docker-compose build && docker-compose up -d
Shut-Down the application
docker-compose down --remove-orphans --volumes