Skip to content

sbouaazzi/book

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

book API

This repository contains a CRUD API to manage a list of Books

API Documentation

  • GET /book
    • retrieves all the books in the list of books
    • example request: localhost:8080/book
    • example 200 response:
      [
          {
              "id": "5cae21aad67494bbc5532bbc",
              "title": "Rat in the Hat",
              "author": "Mr. Suess",
              "publisher": "Random House Inc",
              "publishdate": "2019",
              "rating": 1,
              "status": "CheckedOut"
          },
          {
              "id": "5cae21aad67494bbc5532bbd",
              "title": "Bat in the Hat",
              "author": "Mrs. Suess",
              "publisher": "Random Planet Inc",
              "publishdate": "2015",
              "rating": 1,
              "status": "CheckedIn"
          } 
      ]
      
    • example 400 response:
          {
              error: "Invalid Book ID"
          }
      
  • GET /book/{id}
    • retrieves one book with the specified id parameter
    • example request: localhost:8080/book
    • example 200 response:
        {
            "id": "5cae21aad67494bbc5532bbc",
            "title": "Rat in the Hat",
            "author": "Mr. Suess",
            "publisher": "Random House Inc",
            "publishdate": "2019",
            "rating": 1,
            "status": "CheckedOut"
        }
      
    • example 400 response:
      {
          error: "Invalid Book ID"
      }
      
  • POST /book
    • creates one book with the data values in the message payload
    • example request: localhost:8080/book
          {
          	"title": "Nat in the hat",
          	"author": "Dr. Suess",
          	"publisher": "Random Planet",
          	"publishdate": "1960",
          	"rating": 2,
          	"status": "CheckedOut"
          }
      
    • example 200 response:
        {
            "id": "5cae21aad67494bbc5532bbc",
            "title": "Rat in the Hat",
            "author": "Mr. Suess",
            "publisher": "Random House Inc",
            "publishdate": "2019",
            "rating": 1,
            "status": "CheckedOut"
        }
      
    • example 400 response:
          {
              error: "Invalid Book ID"
          }
      
  • PUT /book/{id}
    • updates one book record with the specified id parameter in the book list
    • example request: localhost:8080/book
          {
             "title": "Nat in the hat",
             "author": "Dr. Suess",
             "publisher": "Random Planet",
             "publishdate": "1960",
             "rating": 2,
             "status": "CheckedOut"
          }
      
    • example 200 response:
         {
              "id": "5cae21aad67494bbc5532bbc",
              "title": "Rat in the Hat",
              "author": "Mr. Suess",
              "publisher": "Random House Inc",
              "publishdate": "2019",
              "rating": 1,
              "status": "CheckedOut"
         }
      
    • example 400 response:
         {
             error: "Invalid Book ID"
         }
      
  • DELETE /book/{id}
    • deletes one book record with the specified id parameter from the book list
    • example request: localhost:8080/book
    • example 200 response:
         {
           Result: Success
         }
      
    • example 400 response:
         {
           error: "Invalid Book ID"
         }
      

Instructions

Prerequisites: Be sure to have the Go environment and Docker installed on the local machine in order for the project to run properly

In order to run this project from a docker container, please follow the following steps:

  • Pull the project from the book github repo
  • Open the project from any IDE
  • From the terminal, navigate to the main /book directory
  • In the terminal from that directory, run the command docker-compose up --build
  • This command will build the MongoDB and Book API Go source images and run the containers
  • When the build is complete, and the containers are running, now access the API running on port 8080
  • Use cURL or PostMan to test the API
  • To run the unit tests:
    • make sure the docker containers are running
    • access the book directory in the terminal
    • run the command go test book/controllers

About

CRUD API to manage a list of Books

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors