This tutorial is designed for those who have not worked with the Spring Framework or rest web services before. I am keeping it simple and less verbose so that readers can easily follow the steps and start developing the restful web services using Spring Data Rest.
Spring Framework
is the trending and widely used J2EE frameworks. It has various modules for web development. In this tutorial, we will use the Spring Data Rest.
RESTful Web services
Representational State Transfer (REST) is based on server-client architecture and uses the HTTP protocol(stateless protocol). CRUD operations can be easily mapped on HTTP methods
Create
| POST |
Read | GET |
Update | PUT |
Delete | Delete |
Prerequisites for this tutorial
- Java 8 or later version
- Eclipse
- Maven
Let's start developing the RESTful web services
STEP 1
Open a new Maven Project in the eclipse, let's call it MyFirstRestApp. We will use the Spring Boot for this tutorial. Open the maven.xml file and add the following dependencies
STEP 2
Create the MyRestApplication.java file
@SpringBootApplication is handling all the configurations behind the screen. It is equivalent to the following three configurations
- @EnableAutoConfiguration
- @ComponentScan
- @Configuration
STEP 3
Now we will move to the Rest web services implementation. For simplicity, I am taking an example of Blog's posts. Create a BlogPostController.java file
- @RestController tells the Spring framework that it is a RESTful web services resource.
- @RequestMapping("/blogPosts") routes every request to /blogPosts to this class
- HTTP methods are routed to the respective operations using the @GetMapping,@PostMapping,@PutMapping and @DeleteMapping annotations.
STEP 4
Run the application as Java application from eclipse
STEP 5
Now, let's test the application. We will use Postman ( a rest client) for this example.
The full source code for this tutorial can be found at MyFirstRestApp .
You will find the following tutorial useful
I hope that you found this tutorial useful. Please leave your feedback in the comments box below.
This comment has been removed by a blog administrator.
ReplyDelete