A simple REST API to manage your reading list, built with Node.js and Express.js .
- Node.js (ESM)
- Express.js
- File-based storage (JSON)
git clone https://github.com/hongdat-pham/book-api.git
cd book-apinpm installPORT=3000
NODE_ENV=development
APP_NAME=Book APInpm startServer will be running at http://localhost:3000
| Method | URL | Description |
|---|---|---|
| GET | / |
API info and available endpoints |
| Method | URL | Description |
|---|---|---|
| GET | /books |
Get all books |
| GET | /books?status=reading |
Filter books by status |
| POST | /books |
Add a new book |
| GET | /books/:id |
Get a single book |
| PATCH | /books/:id |
Update a book |
| DELETE | /books/:id |
Delete a book |
{
"id": 1700000000000,
"title": "The Pragmatic Programmer",
"author": "David Thomas",
"status": "reading",
"createdAt": "2024-01-01T00:00:00.000Z"
}Status values: reading | done | wishlist
curl -X POST http://localhost:3000/books \
-H "Content-Type: application/json" \
-d '{"title": "Clean Code", "author": "Robert C. Martin"}'Response 201:
{
"id": 1700000000000,
"title": "Clean Code",
"author": "Robert C. Martin",
"status": "reading",
"createdAt": "2024-01-01T00:00:00.000Z"
}curl http://localhost:3000/bookscurl http://localhost:3000/books?status=donecurl -X PATCH http://localhost:3000/books/1700000000000 \
-H "Content-Type: application/json" \
-d '{"status": "done"}'curl -X DELETE http://localhost:3000/books/1700000000000Response: 204 No Content
book-api/
├── src/
│ ├── app.js # Express app setup
│ ├── server.js # Start server
│ ├── config.js # Environment config
│ ├── db.js # File-based data store
│ └── routers/
│ └── books.js # Books routes
├── data/
│ └── books.json # Data storage
├── .env # Environment variables (not committed)
├── .gitignore
└── package.json
| Status | Meaning |
|---|---|
| 400 | Missing required fields (title or author) |
| 404 | Book not found |
| 500 | Internal server error |