How to use Rest Template with Spring Boot

This is a very simple demonstration that shows how to use Rest Template with Spring Boot. In this example, I will create Java APIs, using Spring Boot to call another REST API to GET, POST and PATCH data.
To make it done, I'm using another REST application to work as a service. You can clone it using the following git repository. This can be any application that creates REST APIs, maybe Java, PHP, Python or whatever.
This application will run on port 8090. Please read the ReadMe file for API details. Now I am going to create another Spring Boot application to call those APIs using Rest Template.

You can use the following curl command to GET, POST, PATCH and DELETE data. My application is running on port 8088, by default it will run on port 8080. You can change it by setting server. port=8088 at

Get user data

curl -XGET 'http://localhost:8088/api/v2/users/getData/'

Add a new user

curl -XPOST -H "Content-type: application/json" -d '{
    "name": "testUser",
    "email": ""
}' 'http://localhost:8088/api/v2/users/postData/' 

Update a user

curl -XPATCH -H "Content-type: application/json" -d '{
    "email": ""

}' 'http://localhost:8088/api/v2/users/patchData/2'

Remove a user

curl -XDELETE 'http://localhost:8088/api/v2/users/deleteData/2'

You can download the complete project from here. 

How to use Rest Template with Spring Boot How to use Rest Template with Spring Boot Reviewed by Ravi Yasas on 2:56 PM Rating: 5

No comments:

Powered by Blogger.