You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add support for DELETE with body to RestTemplate [SPR-7867] #12524
in: webIssues in web modules (web, webmvc, webflux, websocket)status: declinedA suggestion or change that we don't feel we should currently applytype: enhancementA general enhancement
Spring's annotation-based REST controllers support almost any combination of HTTP method and request/respond payload. For example, it is possible to write a controller method that accepts a DELETE with a request body object.
RestTemplate should IMHO mirror these capabilities and support request/response bodies for all methods regardless of whether a combination is allowed by the REST RFCs.
Alternatively, RestTemplate could make it easier to add support for these combinations in custom subclasses by making its various inner-classes protected.
I just want to add that the server-side Spring WS stuff (org.springframework.web) supports DELETEs with a request body. So I think this ought to be supported by the client side, too.
There is one more caveat: Commons HTTP Client does not support DELETE with body either. This can be worked around by creating a substitute for the built-in DeleteMethod class. The substitute needs to extend EntityEnclosingMethod instead of HttpMethodBase and the CommonsClientHttpRequestFactory needs to instantiate the substitute instead of the original DeleteMethod.
Assigning this to Rossen, but Hannes and Eugen, if either of you are interested in contributing this support, please do! The contributor guidelines explain the process. Cheers!
RestTemplate should IMHO mirror these capabilities and support request/response bodies for all methods
Should PUT also be present in the subject? Both PUT and DELETE can return 204 with no content or 200 with the updated or deleted entity in the body, which may not be identical to the one that was submitted.
Are you talking about DELETE with a body returned in the response or DELETE with a body in the request? I thought you meant the former, which makes sense since the server can return a 200 response with the deleted object, possibly modified, in the body. Why a DELETE with a request body though? There is no mention of that kind of scenario in the HTTP spec.
A request body on DELETE request can make sense if you need to attach some meta-data about the deletion. Even if you do a HTTP delete, you do not have to delete the entity from the database. Perhaps you want to keep it for the purpose of statistics, and therefore just flag it as deleted. And for the purpose of statistic you also want to attach some data about the deletion. You can use http-headers, but I think it can sometimes make more sense to have it in the body.
As long as the HTTP spec do not explicitly disallow a request body for a http verb, I see no reason to block it (or remove it).
I think response body on DELETE request is already supported, but I have not tested it. As long as a response do not have a 204 or 205 status code, a response body should be allowed.
in: webIssues in web modules (web, webmvc, webflux, websocket)status: declinedA suggestion or change that we don't feel we should currently applytype: enhancementA general enhancement
Activity
spring-projects-issues commentedon Aug 17, 2011
Hannes Schmidt commented
I just want to add that the server-side Spring WS stuff (org.springframework.web) supports DELETEs with a request body. So I think this ought to be supported by the client side, too.
There is one more caveat: Commons HTTP Client does not support DELETE with body either. This can be worked around by creating a substitute for the built-in DeleteMethod class. The substitute needs to extend EntityEnclosingMethod instead of HttpMethodBase and the CommonsClientHttpRequestFactory needs to instantiate the substitute instead of the original DeleteMethod.
spring-projects-issues commentedon Apr 22, 2012
Eugen Paraschiv commented
Any news on this one? Since Spring MVC supports the combination, it would make sense to support it in RestTemplate as well.
Thanks.
Eugen.
spring-projects-issues commentedon May 11, 2012
Chris Beams commented
Assigning this to Rossen, but Hannes and Eugen, if either of you are interested in contributing this support, please do! The contributor guidelines explain the process. Cheers!
spring-projects-issues commentedon May 11, 2012
Rossen Stoyanchev commented
Should PUT also be present in the subject? Both PUT and DELETE can return 204 with no content or 200 with the updated or deleted entity in the body, which may not be identical to the one that was submitted.
spring-projects-issues commentedon Jun 1, 2012
Arjen Poutsma commented
Note that bodies for both PUT and DELETE are already supported through the exchange method. For instance, you can do:
or
spring-projects-issues commentedon Jun 22, 2012
Rossen Stoyanchev commented
Are you talking about DELETE with a body returned in the response or DELETE with a body in the request? I thought you meant the former, which makes sense since the server can return a 200 response with the deleted object, possibly modified, in the body. Why a DELETE with a request body though? There is no mention of that kind of scenario in the HTTP spec.
spring-projects-issues commentedon Jun 23, 2012
Nils Fredrik Gjerull commented
A request body on DELETE request can make sense if you need to attach some meta-data about the deletion. Even if you do a HTTP delete, you do not have to delete the entity from the database. Perhaps you want to keep it for the purpose of statistics, and therefore just flag it as deleted. And for the purpose of statistic you also want to attach some data about the deletion. You can use http-headers, but I think it can sometimes make more sense to have it in the body.
As long as the HTTP spec do not explicitly disallow a request body for a http verb, I see no reason to block it (or remove it).
I think response body on DELETE request is already supported, but I have not tested it. As long as a response do not have a 204 or 205 status code, a response body should be allowed.
spring-projects-issues commentedon Jun 25, 2012
Rossen Stoyanchev commented
I'm not sure I understand what's blocking you? What prevents you from using what Arjen suggested above?
spring-projects-issues commentedon Jul 18, 2012
Rossen Stoyanchev commented
Resolving this issue for now. Arjen's suggestion to use the more general exchange method should work.