Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

$resource DELETE doesn't set the Request Body if provided #10128

Closed
pmariduena opened this issue Nov 19, 2014 · 3 comments
Closed

$resource DELETE doesn't set the Request Body if provided #10128

pmariduena opened this issue Nov 19, 2014 · 3 comments

Comments

@pmariduena
Copy link

I know this a similar issue has been closed, but I think it should be added. When I try to set a request body on a delete (array of JSON objects), it is put in the URL as a request params, instead of the request body.

Maybe a custom property could be added to $resource (under "options", say "enableDeleteRequestBody" in addition to already supported "stripTrailingSlashes"), with a warning in the doc that states that this is not the officially Spec-compliant use of a DELETE (use at your own risk).

But I would really like to use it.

It would allow for batch deletes of multiple, non-consecutive objects that represent, say, rows in a database. specifying those rowIds as, say, query string params in the URL, or request headers, is messy. Apache Jetty server is definitely accepting my DELETE body request that I send from POSTman.

@pkozlowski-opensource
Copy link
Member

This is related to #8567. Changing things on $resource-level won't help much as $http doesn't send any body for DELETE requests.

@pkozlowski-opensource
Copy link
Member

So, looking at #4280 the current behaviour is the intentional one. I guess that at the end of a day it boils down to a simple question: should DELETE request be allowed to have body or not. Last time I've checked both specs and backend impls weren't so clear about it :-/

The underlying issue is this one #8567

@daniel-nagy
Copy link

According to the documentation for $resource,

  • non-GET "class" actions: Resource.action([parameters], postData, [success], [error])

Implying that the first parameter, parameters, is optional but this is inconsistent with DELETE methods. For DELETE methods, if only one argument is provided it will be sent as query parameters instead of the request body.

This is because the DELETE method is not considered to have a body.

var hasBody = /^(POST|PUT|PATCH)$/i.test(action.method);

@gkalpak gkalpak modified the milestones: Ice Box, Backlog Mar 23, 2016
gkalpak pushed a commit that referenced this issue Mar 21, 2017
By default, only `PUT`, `POST` and `PATCH` requests have a body, but you can use
`hasBody` to configure any action to either have or not have a body, regardless
of its HTTP method.

Fixes #10128

Closes #12181
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants