This project is a RESTful API for managing books, built using Jakarta EE 11. It follows a layered architecture with clear separation of concerns and includes a simple HTML/JavaScript frontend for interaction.
- RESTful Endpoints: CRUD operations for books with pagination and search.
- Validation: Custom validators for ISBN and business rules (e.g., title length vs. page count).
- Error Handling: Custom exceptions (BadRequest, NotFound) and mappers for consistent error responses.
- Pagination:
GET /bookssupports page and size parameters for paginated results. - Search: Filter books by title, author, ISBN, or combinations.
- Frontend: Simple web interface to add and view books.
- Docker Integration: Containerized setup with MySQL database.
- Testing: Unit, integration, and architecture tests using JUnit, Mockito, RestAssured, and ArchUnit.
- Jakarta EE 11: JAX-RS, CDI, JPA, Bean Validation.
- Hibernate: ORM for database interactions.
- MySQL: Relational database for persistence.
- Docker: Containerization for easy deployment.
- Maven: Build automation and dependency management.
- Presentation:
BookResource(REST controller) handles HTTP requests. - Business:
BookServicecontains business logic, delegates to repository. - Persistence:
BookRepository(Spring Data-style interface) for database operations. - DTOs: Data Transfer Objects (CreateBook, BookResponse, etc.) for API contracts.
- Entities: JPA
Bookentity mapped to the database.
- Docker and Docker Compose
- JDK 21+ (optional for local Maven build)
- Maven (optional)
-
Build and Start Containers:
docker-compose up --build
- Starts MySQL and the Tomcat application server.
- Initializes the database with sample books on first run.
-
Access the Application:
- Frontend:
http://localhost:8080 - API Base URL:
http://localhost:8080/api/books
- Frontend:
-
Package the WAR:
mvn clean package
- Output:
target/rest-api-jakarta-ee11-1.0-SNAPSHOT.war
- Output:
-
Deploy to a Jakarta EE 11 compatible server (e.g., WildFly).
mvn test
Executes unit tests, integration tests, and architecture validation.
API Endpoints
Method Endpoint Description
GET /books Get paginated list of books
GET /books?author={author} Filter books by author
GET /books?title={title} Filter books by title
GET /books/search Search by title/isbn (see docs)
POST /books Create a new book
PATCH /books/{id} Update a book
Frontend Usage
Add a Book: Fill in the form with title, author, ISBN, and page count.
View Books: The table automatically updates with books from the API.
Error Handling: Validation errors display red messages above the form.
Project Structure
.
├── docker-compose.yaml # Docker setup for app and MySQL
├── Dockerfile # Multi-stage build configuration
├── src/
│ ├── main/
│ │ ├── java/ # Java source code
│ │ ├── resources/ # JPA config and SQL scripts
│ │ └── webapp/ # Frontend (HTML, JS, images)
│ └── test/ # Test classes
└── pom.xml # Maven dependencies and plugins