A simple REST API for managing a list of books, built with Express and TypeScript.
- CRUD operations for books
- In-memory storage
- Input validation with Zod
- Modular, class-based design
- Repository pattern & simple dependency injection
- RESTful error handling
- Docker support (development, hot reload)
- Jest tests for all endpoints
- Install dependencies:
npm install
- Start the server (hot reload):
npm run dev
- Run tests:
npm test
- Build the image:
docker build -t books-api . - Run the container:
docker run -p 3000:3000 -v $(pwd):/app books-api
Base URL: http://localhost:3000/api/books
- POST
/api/books - Body:
{ "title": "Book Title", "author": "Author Name", "publishedDate": "2023-01-01", "genre": "Fiction" } - Response:
{ "id": "...", "title": "Book Title", "author": "Author Name", "publishedDate": "2023-01-01", "genre": "Fiction" }
- GET
/api/books - Response:
[ { "id": "...", "title": "Book Title", "author": "Author Name", "publishedDate": "2023-01-01", "genre": "Fiction" } ]
- GET
/api/books/{id} - Response:
{ "id": "...", "title": "Book Title", "author": "Author Name", "publishedDate": "2023-01-01", "genre": "Fiction" }
- PUT
/api/books/{id} - Body: (any subset of fields except
id){ "title": "New Title" } - Response:
{ "id": "...", "title": "New Title", "author": "Author Name", "publishedDate": "2023-01-01", "genre": "Fiction" }
- DELETE
/api/books/{id} - Response:
204 No Content
- Returns JSON error messages with appropriate HTTP status codes.
MIT