This project is a REST API for a book and author management system. The API provides CRUD (Create, Read, Update, Delete) operations for managing books and authors.
- Books API: Allows you to create, read, update, and delete books.
- Authors API: Allows you to create, read, update, and delete authors.
- Pagination: Supports pagination for listing books and authors.
- Nested Objects: Supports mapping of nested objects using Model Mapper.
.
├───src
├───main
│ ├───java
│ │ └───com
│ │ └───tyrien
│ │ └───quickstart
│ │ ├───config
│ │ ├───controllers
│ │ ├───dao
│ │ │ └───impl
│ │ ├───domain
│ │ │ ├───dataTransferObjects
│ │ │ └───entities
│ │ ├───mappers
│ │ │ └───impl
│ │ ├───repositories
│ │ └───services
│ │ └───impl
│ └───resources
│ ├───static
│ └───templates
└───test
├───java
│ └───com
│ └───tyrien
│ └───quickstart
│ ├───controllers
│ ├───dao
│ │ └───impl
│ └───repositories
└───resources
- Create Book:
- Method: PUT
- URL:
/books/{ISBN} - Response on Success: HTTP 201 Created
- Read One Book:
- Method: GET
- URL:
/books/{ISBN} - Response on Success: HTTP 200 with the book as a JSON object
- Response on Not Found: HTTP 404 with an empty response body
- Read Many Books:
- Method: GET
- URL:
/books - Response: HTTP 200 with a list of books, even if it's empty
- Update Book:
- Method: PUT
- URL:
/books/{ISBN} - Response: HTTP 200 for successful update (not HTTP 201)
- Partial Update Book:
- Method: PATCH
- URL:
/books/{ISBN} - Response: HTTP 200 for successful partial update
- Delete Book:
- Method: DELETE
- URL:
/books/{ISBN} - Response: HTTP 204 with no response body
- Create Author:
- Method: POST
- URL:
/authors - Response on Success: HTTP 201 Created with the author object in the response body
- Read One Author:
- Method: GET
- URL:
/authors/{ID} - Response on Success: HTTP 200 with the author object
- Response on Not Found: HTTP 404 if the author is not found
- Read Many Authors:
- Method: GET
- URL:
/authors - Response: HTTP 200 with a list of authors
- Update Author:
- Full Update Method: PUT
- URL:
/authors/{ID} - Response: HTTP 200 for successful full update, replacing the existing author with the provided object
- Partial Update Author:
- Method: PATCH
- URL:
/authors/{ID} - Response: HTTP 200 for successful partial update, updating only the provided attributes
- Delete Author:
- Method: DELETE
- URL:
/authors/{ID} - Response: HTTP 204 with no response body; deletes the author in the database
- Java
- Spring Boot
- Spring Data JPA
- PostgreSQL
- ModelMapper
- JUnit
- MockMvc
- Postman
To run this project, you need to have Java, a Java IDE, Docker and Postman installed on your machine. The Spring Boot dependencies and PostgreSQL database can be installed/configured via your IDE.
- Clone the repository to your local machine.
- Update the
application.propertiesfile with your database credentials. - Start Docker Desktop (for windows) then run
docker-up composein your IDE terminal. - Run maven command
./mvnw clean verifyto ensure build is successful. - Run the application by using the command
./mvnw spring-boot:runor by running the BooksAPIApplication class. - Use Postman or any other API client to interact with the endpoints.
The project includes integration tests written using JUnit and MockMvc. To run the tests, use the command ./mvnw test.
You can also run individual tests inside test classes or all the test of a single class via the IDE.
For further reference, please consider the following sections:
- Official Apache Maven documentation
- Spring Boot Maven Plugin Reference Guide
- Create an OCI image
- Spring Web
The following guides illustrate how to use some features concretely:
- Building a RESTful Web Service
- Serving Web Content with Spring MVC
- Building REST services with Spring
This project is licensed under the MIT License. See the LICENSE file for details.
Please note that this README is a work in progress. If you have any ideas on how to improve it, please feel free to suggest changes.
Notes: When we use Spring JPA database setup via Hibernate, there is no need for the unit test files ( BookDaoImplTest & AuthorDaoImplTest). Also, the following are no longer needed:
- dao package inside main.
- dao package inside test
- schema.sql file inside main package.
What we do is we create the new repositories directory inside the test folder in which we place the integration test files by refactoring and moving them from the doa.impl package. I also change spring-boot-starter-jdbc inside the pom.xml file to spring-boot-starter-data-jpa