This project is a simple RESTful API built with Express.js for managing a collection of books.
This is an API built for managing a collection of books. It allows adding books to the database, updating the loan status of the book, getting all the books in the database or just one particular book and it also allows for the deletion of a book. It is useful in a library setting where one has to keep track of all the books available
Provide step-by-step instructions on how to set up the project locally. To set up the project locally:
- Clone the repository using this link https://github.com/Hephzy-1/books.git
- Navigate to the cloned repository
- Download the dependencies using npm install
# Clone the repository
git clone https://github.com/Hephzy-1/books.git
# Navigate to the project directory
cd books
# Install dependencies
npm install
You can run the project using nodemon
# Start the server
npm start
Your output should be similar to
Server is running on port 3000
Here are the available API endpoints:
This endpoint retrieves all the books in the database.
GET /api/books
200 OK
- Returns all books
400 Bad Request
- Invalid Request
This endpoint retrieves a single book by its id.
GET /api/books/{title}
title
- The title of the book
200 OK
- Returns the book with the specified title
404 Not Found
- Book not found
This endpoint adds a new book to the database. The request body should contain the book details in JSON
POST /api/books
{
"title": "Book Title",
"author": "Author Name"
}
201 Created
- Book added successfully
400 Bad Request
- Invalid input
This endpoint updates a single book by its id. The request body should contain the updated book details in JSON
PUT /api/books/{title}
title
- The title of the book
{
"title": "Book Title",
"loan": true
}
200 OK
- Book updated successfully
404 Not Found
- Book not found
This endpoint deletes a single book by its id.
DELETE /api/books/{title}
title
- The title of the book
{
"title": "Book Title"
}
200 OK
- Book deleted successfully
404 Not Found
- Book not found