shashank-kakarla / BookAPI

BookAPI written in Golang using Gin and GORM

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Book API

The project is a Book API written in Golang using libraries like Gin and GORM. This API performs all the CRUD operations like -

  1. Create a New Book with Title and Author.
  2. Retrieve all the Books that exist in the Database.
  3. Retrieve the Books with the given ID (automatically generated at creation).
  4. Retrieve the Book with the given Title.
  5. Retrieve all the Books with the given Author.
  6. Delete a Book with given ID.
  7. Update the Title or Author of a Book with given ID.

Packages

Gin

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

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

API Reference

Get all items

  GET /books

Get Book with given ID

  GET /books/:id
Parameter Type Description
id uint Required. Id of item to fetch

Get Book with given Title

  GET /books/title/:title
Parameter Type Description
title string Required. Id of item to fetch

Get Book with given Author

  GET /books/author/:author
Parameter Type Description
author string Required. Id of item to fetch

Create Book with given Author and Title

This operation here also prevents creation of duplicate data.

  POST /books
  • Request Body Example -
{
    "title": "Fairy tales",
    "author": "Hans Christian Andersen"
}

Update Book with given Author and Title for the ID

  PATCH /books/:id
  • Example 1
{
    "title": "Fairy tales"
}
  • Example 2
{
    "author": "Stephenie Meyer"
}
  • Example 3
{
    "title": "Twilight"
    "author": "Stephenie Meyer"
}

DELETE Book with given Author and Title for the ID

  DELETE /books/:id
Parameter Type Description
id uint Required. Id of item to delete

Deploy BookAPI

Developed dockerfile to build and run the bookapi service, Inorder to attach Database used MySql as a database and implemented docker-compose

Pre-requisites

  1. Git
  2. docker
  3. 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 

About

BookAPI written in Golang using Gin and GORM

License:MIT License


Languages

Language:Go 89.4%Language:Dockerfile 8.6%Language:Shell 1.9%