Made to learn implementation of REST API in Java and DTO Model Conversion.
This is a simple Spring Boot REST API for managing books, in this scenario for library.
It demonstrates clean separation of Model and DTO, validation with @Valid, and the use of H2 for the database.
- Java 17+
- Spring Boot (Web, Validation, Data JPA)
- Lombok (for @Data, @RestContoller, and etc.)
- H2 Database (In-memory for testing)
- Maven (Dependency Management)
Part of program that represents the actual database entity. Code is here
A simpler version of object, used to send/receive data in API calls. It prevents exposing the full database structure and allow customizing request/response fields. Code is here
Request -> Controller -> Service -> Repository -> Database and back.
Example Scenario:
- User sends
POST /bookswith JSON Body
{
"title": "The Hobbit",
"author": "J.R. Tolkien",
"quantity": 30
}- Controller receives
BookDTO(@Validruns validation). - Service converts DTO to Model
- Repository saves Model to DB
- Response is sent back as BookDTO
{
"title": "The Hobbit",
"author": "J.R. Tolkien",
"quantity": 30
}