Skip to content

Patti88/rest-api-jakarta-ee11

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Book Manager REST API


Implementation Description

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.

Key Features

  • 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 /books supports 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.

Technologies

  • 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.

Architecture Layers

  • Presentation: BookResource (REST controller) handles HTTP requests.
  • Business: BookService contains 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 Book entity mapped to the database.

Building and Running the Application

Prerequisites

  • Docker and Docker Compose
  • JDK 21+ (optional for local Maven build)
  • Maven (optional)

Using Docker (Recommended)

  1. Build and Start Containers:

    docker-compose up --build
    • Starts MySQL and the Tomcat application server.
    • Initializes the database with sample books on first run.
  2. Access the Application:

    • Frontend: http://localhost:8080
    • API Base URL: http://localhost:8080/api/books

Local Maven Build

  1. Package the WAR:

    mvn clean package
    • Output: target/rest-api-jakarta-ee11-1.0-SNAPSHOT.war
  2. Deploy to a Jakarta EE 11 compatible server (e.g., WildFly).

Running Tests

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors