This is a simple RESTful API for managing a collection of books. It allows you to perform basic CRUD (Create, Read, Update, Delete) operations on books stored in a MongoDB database.
- Endpoint:
POST /api/books
- Usage: Create a new book by sending a JSON object with the book's information (title, author, summary) in the request body.
Example Request:
POST /api/books
{
"title": "Sample Book",
"author": "John Doe",
"summary": "A sample book summary."
}
- Endpoint:
GET /api/books
- Usage: Retrieve a list of all books in the database.
Example Request:
GET /api/books
- Endpoint:
GET /api/books/:id
- Usage: Retrieve the details of a specific book by specifying its ID in the URL parameter.
Example Request:
GET /api/books/123456789012345678901234
- Endpoint:
PUT /api/books/:id
- Usage: Update the details of a specific book by specifying its ID in the URL parameter and sending a JSON object with the updated book information in the request body.
Example Request:
PUT /api/books/123456789012345678901234
{
"title": "Updated Book Title",
"author": "Jane Smith",
"summary": "An updated book summary."
}
- Endpoint:
DELETE /api/books/:id
- Usage: Delete a specific book by specifying its ID in the URL parameter.
Example Request:
DELETE /api/books/123456789012345678901234
To set up and run this application on your local machine, follow these steps:
git clone <repository_url>
cd book-management-api
PORT=3000
MONGO_USERNAME=<YourMongoDBUsername>
MONGO_PASSWORD=<YourMongoDBPassword>
Replace YourMongoDBUsername and YourMongoDBPassword with your MongoDB credentials.
npm install
npm start