This is a simple REST API for managing a list of books. It supports operations to create, read, update, and delete books.
- Installation
- Setup
- Running the Server
- API Endpoints
- Get All Books
- Get a Book by ID
- Create a New Book
- Update an Existing Book
- Delete a Book
- Testing the API
First, make sure you have Node.js installed. Then, clone the repository.
git clone https://github.com/subhamadhikari/BookManagementAPI.git
cd BookManagementAPI
Ensure you have the necessary dependencies installed by running:
npm install
To start the server, use the following command:
npm start
- URL: /bookAPI/books
- Method: GET
- Success Response:
- Code: 200 OK
- Content: {"book": [{ "id": "1717215862912", "title": "Harry Potter", "author": "JK Rowling", "year": 1996 }, ...]}
-
URL: /bookAPI/books/:bookID
-
Method: GET
-
URL Params: bookID=[string]
-
Success Response:
- Code: 200 OK
- Content: {"message": "Book Found!", "book": [{ "id": "1717215862912", "title": "Harry Potter", "author": "JK Rowling", "year": 1996 }]}
-
Error Response:
- Code: 404 Not Found
- Content: {"message": "Book not found"}
-
URL: /bookAPI/books
-
Method: POST
-
Data Params:
{"title": "string", "author": "string", "year": "number"}
-
Success Response:
- Code: 201 Created
- Content: {"message": "Book created successfully!", "book": { "id": "1717215862913", "title": "New Book", "author": "Author", "year": 2023 }}
-
Error Response:
- Code: 400 Bad Request
- Content: {"message": "Enter all the required fields", "book": null}
-
URL: /bookAPI/books/:bookID
-
Method: PUT
-
URL Params: bookID=[string]
-
Data Params:
{"title": "string", "author": "string", "year": "number"}
-
Success Response:
- Code: 200 OK
- Content: {"message": "Book has been successfully updated", "book": { "id": "1717215862912", "title": "Updated Title", "author": "Updated Author", "year": 2023 }}
-
Error Response:
- Code: 404 Not Found
- Content: {"message": "Book not found"}
-
URL: /bookAPI/books/:bookID
-
Method: DELETE
-
URL Params: bookID=[string]
-
Success Response:
- Code: 200 OK
- Content: {"message": "Book deleted successfully!", "book": { "id": "1717215862912", "title": "Deleted Book", "author": "Deleted Author", "year": 2023 }}
-
Error Response:
- Code: 404 Not Found
- Content: {"message": "Book not found"}
You can test the API endpoints using a tool like Postman.
- Method: GET
- URL: http://localhost:5050/bookAPI/books
- Method: GET
- URL: http://localhost:5050/bookAPI/books/:bookID
- Method: POST
- URL: http://localhost:5050/bookAPI/books
- Body:
{
"title": "New Book",
"author": "Author",
"year": 2023
}
- Method: PUT
- URL: http://localhost:5050/bookAPI/books/:bookID
- Body:
{
"title": "Updated Title",
"author": "Updated Author",
"year": 2023
}
- Method: DELETE
- URL: http://localhost:5050/bookAPI/books/:bookID