Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do a PUT using RestTemplate

I can do this for POST

ResponseEntity<ResponseMessage> response = restTemplate.postForEntity(URL, animal, ResponseMessage.class);
return response.getBody();

But why there is no putForEntity for PUT? There is just resTemplate.put(...

How do I do it for 'PUT' request.

like image 215
Alvin Avatar asked Aug 13 '26 06:08

Alvin


2 Answers

You can use:

restTemplate.exchange(url, HttpMethod.PUT, requestEntity, ...)

Here is the link to the documentation of this method.

like image 134
Razvan Avatar answered Aug 14 '26 22:08

Razvan


You can use PUT instead, reason why putForEntity is not available because as per standard PUT will not return a response body but 201 or 200 in most of the cases.

like image 28
Yogesh Prajapati Avatar answered Aug 14 '26 20:08

Yogesh Prajapati



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!