RestTemplate delete with authentication using headers in Spring




Asked on February 25, 2017
I am creating a spring web service application client. I have to pass headers to authenticate the user. How to delete a resource using RestTemplate API with authentication. 




Replied on February 25, 2017

To delete a resource using RestTemplate we can use its method that uses HTTP DELETE method.

RestTemplate has two methods that can use HTTP DELETE method.


a.  RestTemplate.delete()


b. RestTemplate.exchange()

 

When we use RestTemplate.delete(), we are not able to pass headers for authentication. But if we use RestTemplate.exchange(), we can achieve our goal as follows.

 

restTemplate.exchange(url, HttpMethod.DELETE, request, Void.class, 1); 

 

 

 




Replied on February 25, 2017
Its working. Thanks Mukesh.

Write Answer










©2024 concretepage.com | Privacy Policy | Contact Us