Swpno
Swpno

Reputation: 183

Spring boot: Using Rest template make post call

I need to make a post call using following details using rest template:

I need to send json with 4/5 parameters, need to set headers for content type and accept, and method with be post.

Can you please help me with sample code to create the json object and set the headers and make the post call

Upvotes: 0

Views: 746

Answers (1)

barbakini
barbakini

Reputation: 3144

You can use postForObject method directly. You can give java object and for accept a response class.

SomeRequestObject obj1 = new SomeRequestObject();
SomeResponseObject response = restTemplate.postForObject("url-to-service", obj1, SomeResponseObject.class);

Upvotes: 1

Related Questions