This is a RESTful API for a Library Management System built using Spring Boot. It allows users to register as borrowers or admins and perform actions related to book management and borrowing.
- Authentication & Authorization (JWT-based Security)
- Role-based Access Control (Admin vs. Borrower Permissions)
- Book Management (Admin only)
- Borrowing System (Checkout/Return Books)
- Borrowing Reports (Admin only)
- Code Quality & Analysis (SonarQube)
- Rate Limiting (Prevent excessive API requests)
- Extra Data in API Responses (Optional metadata for debugging & analytics)
- Swagger API Documentation (Interactive API exploration)
- Docker (Containerized deployment)
HTTP Verbs | Endpoints | Action |
---|---|---|
POST | /api/auth/register/borrower |
Register a new borrower |
POST | /api/auth/register/admin |
Register a new admin |
POST | /api/auth/login |
Login as an admin or borrower |
-
Upon successful login, users receive a JWT Token.
-
The token must be included in the Authorization header as a Bearer Token in subsequent requests.
-
Example:
Authorization: Bearer your-jwt-token
-
Endpoints marked as Admin only require an admin role to access.
HTTP Verbs | Endpoints | Action |
---|---|---|
GET | /api/books |
Get all books(with filter) |
GET | /api/books/{id} |
Get a single book by ID |
POST | /api/books |
Add a new book (Admin only) |
PUT | /api/books/{id{ |
Update a book (Admin onlu) |
DELETE | /api/books/{id} |
Delete a book (Admin only |
HTTP Verbs | Endpoints | Action |
---|---|---|
GET | /api/borrowings/ |
Get borrowered books for the current borrower |
POST | /api/borrowings/checkout |
Borrow a book |
POST | /api/borrowings/return |
Return a borrowed book |
HTTP Verbs | Endpoints | Action |
---|---|---|
GET | /api/borrowings/overdue |
Get overdue books |
GET | /api/borrowings/active |
Get active borrowings |
GET | /api/borrowings/active/{borroerId} |
Get active borrowings by borrower ID |
GET | /api/borrowings/report?startDate={}&endDate={} |
Generate a borrowing report |
GET | /api/borrowings/export?startDate={}&endDate={}&format={} |
Export borrowing reports |
- Spring Boot (Java)
- Spring Security (JWT Authentication & Authorization)
- Spring Data JPA (Database Access)
- MySQL (Database)
- Lombok (Reduces Boilerplate Code)
- SonarQube (Static Code Analysis & Quality Assurance)
- Swagger UI (API Documentation & Testing)
- Docker (Containerized Deployment)
This project includes Rate Limiting to prevent excessive API requests. A custom annotation @RateLimited is used to enforce request limits per endpoint.
Example Usage:
@RateLimited
@GetMapping()
public ResponseEntity<ApiResponse<BookFetchResponse>> fetchBooks(
HttpServletRequest httpRequest,
@RequestParam(defaultValue = "false") boolean includeExtraData,
@ModelAttribute BookFetchRequest bookFetchRequest
) {
BookFetchResponse response = bookService.findAll(bookFetchRequest);
return extraDataUtil.buildResponse(httpRequest, includeExtraData, response, HttpStatus.OK);
}
This project includes an Extra Data Utility that allows API responses to include additional metadata when requested.
- Users can pass
?includeExtraData=true
in API requests - Extra metadata includes:
- TImestamp
- Response size
- Request ID
- Server Info
- API version
- Client IP address
- User-Agent
Example Response with Extra Data:
{
"status": 200,
"data": {
"id": 1,
"title": "Clean Code",
"Author":"Robert Cecil Martin"
"quantity":20
},
"extraData": {
"timestamp": "2025-03-19T12:34:56Z",
"responseSize": 256,
"requestId": "abc-123",
"serverInfo": "Library API Server v1.0",
"clientIp": "192.168.1.1",
"apiVersion": "v1",
"userAgent": "PostmanRuntime/7.29.0"
}
}
Swagger UI is available for interactive API testing and documentation.
- Open a browser and navigate to:
http://localhost:8080/swagger-ui.html
- Explore and test API endpoints directly from the interface.
- OpenAPI JSON documentation can be accessed at:
http://localhost:8080/v3/api-docs