Hello everyone,
Greetings today!
Today we will use spring boot to create a REST API for CRUD operations.
The APIs that we will be developing at the end are listed below.
Get All Books [HTTP Method -GET & Request URL - localhost:8080/book]
GET Book By Id [HTTP Method -GET & Request URL - localhost:8080/book/{bookId}]
Add Book [HTTP Method -POST & Request URL - localhost:8080/book]
Request Payload
Delete Book [HTTP Method- Delete & Request URL - localhost:8080/book/{bookId}]
Update Book [Http Method -PUT & Request URL - localhost:8080/book/{bookId}]
So let's get started.
Go to spring initialize and create a basic project structure with the dependencies listed below. And then open the project in the IDE.
Now that we're using the Oracle database, let's add an oracle dependency to the pom.xml file.
Below is the project structure we will be developing.
Now, in application.properties, add database-related configuration.
Let's create tables and sequences to store books.
Let's now create a model class that will be mapped to the Books tables. We'll also include the JSON property we want to return as a response.
We will now add repository layer code to the JPA repository, which will provide basic methods such as save, delete, findById, and so on.
As previously stated, we will create a REST endpoint in our controller by using the POST, GET, DELETE, and PUT HTTP methods for operations such as create, read, delete, and update.
So, congratulations, we have finished this example.
Visit Spring Boot REST API File Upload With JSON Data In Single API Call to learn how we can upload files along with JSON data.
Refer to Spring Boot REST API Validation Using Annotations to learn how to validate REST API Requests.
Thanks
Enjoy your learning!
Another post you can refer to is
Spring Boot REST API Export To Excel Using Apache POI
Spring Batch Example Database To CSV Export
Set-Up Liquibase With Spring Boot
Spring MVC CRUD + Spring Boot + Oracle + Thymeleaf
Hibernate CRUD Example Using JSP & Servlet + MySQL + Maven
0 Comments
If you have any doubts let me know.