A simple, extensible RESTful API for managing books and borrowers in a library system. Built with Spring Boot, Java 17, and Docker.
- Register new borrowers (unique email).
- Register new books (ISBN-based, supports multiple copies).
- Borrow and return books (one copy per borrower at a time, prevents double-borrow).
- ISBN number uniquely identifies a book in the following way:
- 2 books with the same title and same author but different ISBN numbers are considered as different books.
- 2 books with the same ISBN numbers must have the same title and same author.
- Multiple copies of books with same ISBN number are allowed in the system
- List all books with borrowing status.
- List all registered borrowers.
- Clear validation and error handling (friendly 404s).
- Interactive API documentation with Swagger (OpenAPI 3).
- Completely portable via Docker.
- Java 17
- Spring Boot 3
- Gradle
- H2 (in-memory database, can be swapped for Postgres/MySQL)
- Docker (optional, for containerized usage)
- Java 17+ JDK (for direct build/run)
- Docker (for containerized usage)
- Git
git clone https://github.com/cynic123/Library-Management.git
cd Library-ManagementOption 1: With Docker (Recommended), No need for Java/Gradle installed!
docker build -t library-api .
docker run -p 8080:8080 library-apiOption 2: Locally with Gradle
./gradlew clean build
./gradlew bootRunApp will be available at http://localhost:8080/library/
| Method | Endpoint | Description |
|---|---|---|
| POST | /library/borrowers | Register a new borrower |
| GET | /library/borrowers | List all borrowers |
| POST | /library/books | Register a new book |
| GET | /library/books | List all books |
| POST | /library/borrow/{borrowerId}/book/{bookId} | Borrow a book by ID |
| POST | /library/return/{borrowerId}/book/{bookId} | Return a borrowed book |
Visit http://localhost:8080/swagger-ui.html (Or sometimes swagger-ui/index.html) for full interactive OpenAPI docs.
- Returns 404 with error reason if a book/borrower is not found.
- Returns 400 for validation errors or bad requests.
- Modification is open for handling any specific 5xx business errors.
Example:
{
"error": "Book not found"
}- Uses H2 in-memory database by default (great for quick testing).
- To use Postgres/MySQL, set environment variables like:
SPRING_DATASOURCE_URL, SPRING_DATASOURCE_USERNAME, SPRING_DATASOURCE_PASSWORD
Pull requests welcome! Please open an issue first to discuss major changes.
Prithwish Samanta