Welcome to the Book API repository! This API allows you to manage a collection of books with features for creating, updating, retrieving, and deleting books. It also supports pagination and filtering.
This API is designed for testers to test the functionality of the endpoints, ensure that the API behaves as expected, and identify any issues during local development and remote deployment.
- CRUD Operations: Create, Read, Update, Delete books.
- Pagination: Retrieve books with pagination support.
- Filtering: Filter books by title, description, and pages.
- Authentication: Secure endpoints with token-based authentication.
- Validation: Ensure data integrity with comprehensive validation rules.
Description: Authenticate users and receive a JWT token.
Request Body:
{
"username": "your-username",
"password": "your-password"
}Responses:
200 OK: { "token": "your-jwt-token" }
401 Unauthorized: Invalid credentials.
Request Body:
{
"title": "Book Title",
"description": "Book Description",
"pages": 300
}Responses:
201 Created: The created book object.
400 Bad Request: Validation errors or if id is provided.{
"title": "Updated Title",
"description": "Updated Description",
"pages": 350
}Responses:
- 200 OK: The updated book object.
- 400 Bad Request: Missing fields or trying to update id.
- 404 Not Found: Book with the specified id does not exist.
Request Body:
{
"title": "Updated Title",
"description": "Updated Description",
"pages": 350
}Responses:
- 204 No Content: Book successfully deleted.
- 404 Not Found: Book with the specified id does not exist.
Responses:
- 204 No Content: All books successfully deleted.
- Pagination & Filtering
Query Parameters:
- page: Page number (default: 1)
- limit: Number of books per page (default: 10)
Responses:
- 200 OK: List of books for the specified page.
Query Parameters:
- title: Title to filter by
Responses:
- 200 OK: List of books matching the title filter.
Query Parameters:
- description: Description to filter by
Responses:
- 200 OK: List of books matching the description filter.
Query Parameters:
- pages: Number of pages to filter by
Responses:
- 200 OK: List of books matching the pages filter.
Ensure you have the following installed on your local machine:
- Clone the repository:
git clone https://github.com/your-username/book-api.git
- Navigate to the project directory:
cd book-api - Install the dependencies:
npm install
To start the API server, run:
npm run devThe server will be running at http://localhost:3000.
Create a .env file in the root directory and add the following variables:
SECRET_KEY=your-secret-key
ADMIN_USERNAME=your-admin-username
ADMIN_PASSWORD=your-admin-password
- Express: Fast, unopinionated, minimalist web framework for Node.js.
- TypeScript: Superset of JavaScript that compiles to plain JavaScript.
- Swagger: API documentation tool.
- jsonwebtoken: JSON Web Token implementation.
- uuid: Library to generate unique identifiers.
- fs-extra: Extension of Node.js fs module with more functionality.
Feel free to contribute to this project! Please fork the repository and submit pull requests with your improvements or bug fixes.