Code Monkey home page Code Monkey logo

bookstore-rest-api's Introduction

What tools did I use to develop this application?

  • Javascript
  • NodeJs (Version 18)
  • Express
  • Mongodb
  • Mongoose
  • Nodemon and dotenv as developer tool

How to run this application

  • Install dependencies with npm install
  • Initialize the server: npm run dev
  • Test the endpoint in Postman or similar: http://localhost:3000
  • Replace the .env.example with .env and update it with your environment variables according to your machine and configurations.

List Books

Returns a list of all books.

  • URL /books

  • Method: GET

  • Successful Response:

    • Code: 200
    • Content:
      [
        {
          "_id": "65a0299f6e610a5cd290bbec",
          "title": "Harry Potter",
          "publisher": "Classics",
          "price": 10,
          "pages": 240
        },
        // Other books...
      ]

Get Book by ID

Returns a specific book based on the provided ID.

  • URL /books/:id

  • Method: GET

  • URL Parameters:

    • id (integer) - Unique ID of the book to be retrieved.
  • Successful Response:

    • Code: 200
    • Content:
      {
          "_id": "65a0299f6e610a5cd290bbec",
          "title": "Harry Potter",
          "publisher": "Classics",
          "price": 10,
          "pages": 240
      }

Register New Book

Registers a new book in the database.

  • URL /books

  • Method: POST

  • Request Body:

      {
          "title": "Harry Potter",
          "publisher": "Classics",
          "price": 10,
          "pages": 240
      }

Successful Response:

  • Code: 201 (Created)
  • Content:
    {
        "id": "65a0299f6e610a5cd290bbec",
        "title": "Harry Potter",
        "publisher": "Classics",
        "price": 10,
        "pages": 240
    }

Update Book by ID

Updates the information of a specific book based on the provided ID.

  • URL /books/:id

  • Method: PUT

  • URL Parameters:

    • id (integer) - Unique ID of the book to be updated.
  • Request Body:

    {
        "title": "Harry Potter New",
        "publisher": "Classics",
        "price": 10,
        "pages": 270
    }

Successful Response:

  • Code: 200
  • Content:
    {
        "title": "Harry Potter New",
        "publisher": "Classics",
        "price": 10,
        "pages": 270
    }

Delete Book by ID

Deletes a specific book based on the provided ID.

  • URL /books/:id

  • Method: DELETE

  • URL Parameters:

    • id (string) - Unique ID of the book to be deleted.
  • Successful Response:

    • Code: 204 (No Content)
    • Content: None
  • Error Response:

    • Code: 500 (Internal Server Error)
    • Content:
    {
        "message": "Failed to delete the book"
    }

1. List Authors

  • URL: /authors

  • Method: GET

  • Successful Response:

    • Code: 200

    • Content:

      [   
        {     
          "id": "aspasldaspldq123",     
          "name": "Author name",     
          "nationality": "American"   
        },   
        // Other authors...
      ]

2. Get Author by ID

  • URL: /authors/:id

  • Method: GET

  • URL Parameters:

    • id (integer) - Unique ID of the author to be retrieved.
  • Successful Response:

    • Code: 200
    • Content:
        {     
          "id": "aspasldaspldq123",     
          "name": "Author name",     
          "nationality": "American"   
        },   

3. Register a New Author

  • URL: /authors

  • Method: POST

  • Request Body:

      {
        "name": "Jane Smith",
        "nationality": "British"
      }
  • Successful Response:

    • Code: 201 (Created)
    • Content:
      {
        "id": "dkqkeqkdk213sdfmatt8",
        "name": "Jane Smith",
        "nationality": "British"
      }

4. Update Author by ID

  • URL: /authors/:id

  • Method: PUT

  • URL Parameters:

    • id (integer) - Unique ID of the author to be updated.
  • Request Body:

      {
        "nationality": "Canadian"
      }
  • Successful Response:

    • Code: 200
    • Content:
      {
        "id": "dkqkeqkdk213sdfmatt8",
        "name": "Jane Smith",
        "nationality": "Canadian"
      }

5. Delete Author by ID

  • URL: /authors/:id

  • Method: DELETE

  • URL Parameters:

    • id (integer) - Unique ID of the author to be deleted.
  • Successful Response:

    • Code: 204 (No Content)
    • Content: None
  • Error Response:

    • Code: 500 (Internal Server Error)

    • Content:

          {   "message": "Failed to delete the author" }
      

bookstore-rest-api's People

Contributors

ebagabe avatar

Stargazers

Joyce Kepler avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.