Skip to content

Add support for DELETE with body to RestTemplate [SPR-7867] #12524

Closed

Description

@spring-projects-issues

Hannes Schmidt opened SPR-7867 and commented

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.


Affects: 3.0.5

Issue Links:

5 votes, 7 watchers

Activity

  1. spring-projects-issues commented on Aug 17, 2011

    @spring-projects-issues
    CollaboratorAuthor

    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.

  2. spring-projects-issues commented on Apr 22, 2012

    @spring-projects-issues
    CollaboratorAuthor

    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.

  3. spring-projects-issues commented on May 11, 2012

    @spring-projects-issues
    CollaboratorAuthor

    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!

  4. spring-projects-issues commented on May 11, 2012

    @spring-projects-issues
    CollaboratorAuthor

    Rossen Stoyanchev commented

    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.

  5. spring-projects-issues commented on Jun 1, 2012

    @spring-projects-issues
    CollaboratorAuthor

    Arjen Poutsma commented

    Note that bodies for both PUT and DELETE are already supported through the exchange method. For instance, you can do:

    ResponseEntity<String> response = template.exchange("http://example.com", HttpMethod.DELETE, null, String.class);
    

    or

    HttpEntity<String> request = new HttpEntity<String>("Hello World");
    ResponseEntity<String> response = template.exchange("http://example.com", HttpMethod.PUT, request, String.class);
    
  6. spring-projects-issues commented on Jun 22, 2012

    @spring-projects-issues
    CollaboratorAuthor

    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.

  7. spring-projects-issues commented on Jun 23, 2012

    @spring-projects-issues
    CollaboratorAuthor

    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.

  8. spring-projects-issues commented on Jun 25, 2012

    @spring-projects-issues
    CollaboratorAuthor

    Rossen Stoyanchev commented

    I'm not sure I understand what's blocking you? What prevents you from using what Arjen suggested above?

  9. spring-projects-issues commented on Jul 18, 2012

    @spring-projects-issues
    CollaboratorAuthor

    Rossen Stoyanchev commented

    Resolving this issue for now. Arjen's suggestion to use the more general exchange method should work.

  10. added
    status: declined
    type: enhancement
    in: web
    on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: webstatus: declinedtype: enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions