- This project demonstrates the usage of Spring Data REST to create A RESTful API from JPA data models.
-
The main objective of this demo is to provide a simple yet comprehensive example of building a web application with Spring Data REST.
-
The project emphasizes the usage of Spring Data REST to expose JPA entities as a RESTful API, simplifying API development without requiring explicit controller logic.
- Automatic exposure of JPA entities as RESTful API.
- CRUD operations management on entities via REST endpoints.
- Spring Data Rest follows a naming convention to expose RESTful endpoints based on JPA entities. Here's samurazed table outlining this convention:
Endpoint | HTTP Method | Description |
---|---|---|
{entity} | GET | Retrieves the complete list of entities. |
{entity} | POST | Create a new entity. |
{entity}/{id} | GET | Retrieves the details of a specific entity. |
{entity}/{id} | PUT | Updates the information of an existing entity. |
{entity}/{id} | DELETE | Delete an existing entity. |
- The API endpoints are automatically generated by Spring Data REST and can be explored using the Swagger OpenAPI UI.
- After launching the application, you can access the Swagger documentation here.
- Alternatively, you can simply refer to the table below, which displays the available endpoints.
Authors Endpoints
Endpoint | HTTP Method | Description |
---|---|---|
authors | GET | Retrieves the complete list of authors. |
authors | POST | Create a new author. |
authors/{id} | GET | Retrieves the details of a specific author. |
authors/{id} | PUT | Updates the information of an existing author. |
authors/{id} | DELETE | Delete an existing author |
Books Endpoints
Endpoint | HTTP Method | Description |
---|---|---|
books | GET | Retrieves the complete list of books. |
books | POST | Create a new book. |
books/{id} | GET | Retrieves the details of a specific book. |
books/{id} | PUT | Updates the information of an existing book. |
books/{id} | DELETE | Delete an existing book |
spring-data-rest-demo/
│
├── src/
│ ├── main/
│ │ ├── java/
│ │ │ └── com/
│ │ │ └── tmane/
│ │ │ └── springdatarestdemo/
│ │ │ ├── entity/
│ │ │ │ ├── Author.java
│ │ │ │ └── Book.java
│ │ │ ├── repository/
│ │ │ │ ├── AuthorRepository.java
│ │ │ │ └── BookRepository.java
│ │ │ └── SpringDataRestDemoApplication.java
│ │ │
│ └── resources/
│ └── application.properties
│
├── pom.xml
└── README.md
- Spring Boot
- Spring Data JPA
- Spring Data REST
- Swagger OpenAPI
- MySQL Database
- For any inquires or feedback regarding this project, please contact me on: [email protected].
End
Author: Tmane Chouaib