This API allows you to manage a collection of books. You can perform various operations like adding a book, retrieving a list of books, getting book details, updating a book, and deleting a book.
- NodeJS Version 16+
- MongoDB Version 7.0
- Git
- Code Editor
- Open terminal or command prompt
- Navigate to folder where you want to clone the repository
- Clone the repository from GitHub
git clone https://github.com/your-repo-url.git
- Navigate to cloned project directory
cd books-manager-api
- Install the project dependencies using npm
npm install
- Create .env file in the root directory of the cloned project and add following variables
PORT=3000 DB_HOST=mongodb://localhost:27017/books_manager_db
- Run the application using below command
npm start
You can use tools like Postman or VS Code Thunder Client Extension to test the API endpoints locally. The base URL for local testing is usually http://localhost:port/api/, where port is the port number mentioned when you started the application.
The base URL for all API endpoints is: https://bookmanager-rrb8.onrender.com/api
This API does not require authentication for now. Ensure that your requests are made over HTTPS for security.
This API returns standard HTTP status codes to indicate the success or failure of a request. In case of an error, additional error details may be provided in the response body.
- 200 OK: The request was successful.
- 201 Created: The resource was successfully created.
- 400 Bad Request: The request was malformed or invalid.
- 404 Not Found: The requested resource was not found.
- 500 Internal Server Error: An error occurred on the server.
POST /add-book
Add a new book to the collection.
Request Body:
{
"title": "JavaScript: The Good Parts",
"author": "Douglas Crockford ",
"summary": "Most programming languages contain good and bad parts, but JavaScript has more than its share of the bad, having been developed and released in a hurry before it could be refined. This authoritative book scrapes away these bad features to reveal a subset of JavaScript that's more reliable, readable, and maintainable than the language as a whole—a subset you can use to create truly extensible and efficient code."
}
Response:
-
201 Created: New book successfully added. Returns the newly created book.
-
400 Bad Request: If the request body is invalid or missing required fields.
GET /books
Retrieve a list of all books in the collection.
Response:
- 200 OK: Returns a list of all books in the collection.
GET /book/:id
Retrieve the details of a specific book by its ID.
Parameters:
id
(string): The unique ID of the book.
Response:
-
200 OK: Returns the details of the requested book.
-
404 Not Found: If the book with the provided ID does not exist.
PUT /book/:id
Update the details of a specific book by its ID.
Parameters:
id
(string): The unique ID of the book.
Request Body:
{
"title": "JavaScript: The Good Parts - Updated",
"author": "Douglas Crockford Updated",
"summary": "Most programming languages contain good and bad parts, but JavaScript has more than its share of the bad, having been developed and released in a hurry before it could be refined. This authoritative book scrapes away these bad features to reveal a subset of JavaScript that's more reliable, readable, and maintainable than the language as a whole—a subset you can use to create truly extensible and efficient code."
}
Response:
-
200 OK: The book was successfully updated. Returns the updated book.
-
400 Bad Request: If the request body is invalid or missing required fields.
-
404 Not Found: If the book with the provided ID does not exist.
DELETE /book/:id
Delete a specific book by its ID.
Parameters:
id
(string): The unique ID of the book.
Response:
-
204 No Content: The book was successfully deleted.
-
404 Not Found: If the book with the provided ID does not exist.
I have deployed this API on Render.com which can be accessed at base api URL https://bookmanager-rrb8.onrender.com/api
.
- Created a free account on https://render.com/
- Added a new web service by clicking on Add New + button there
- Then deployed directly from my GIT repository
- Run the following command in Render.com project setting wizard
npm install
npm start
- Updated the ENVIRONMENT VARIABLES
PORT=3000 DB_HOST=My atlas mongodb connection string NODE_VERSION=16.0.0
Test: Get list of books by hitting https://bookmanager-rrb8.onrender.com/api/books
in your browsers address bar or use any tools like Postman or Thunder Client.
This API allows you to manage a collection of books by providing endpoints for adding, retrieving, updating, and deleting books. Please make sure to use the correct HTTP methods and provide valid request bodies where required.