3

I have standard angular $resource configured as such

angular.module('client.resources')

.factory('ProjectSubjectResource',['$resource',
    function ($resource) {
            release: {
                method: 'DELETE',
                isArray: false
            }
        });
    }]);

and I am calling this method as

ProjectSubjectResource.release({projectId: projectId, subjectId: 0},{ subjectIds: subjectIdArray})

where subjectIdArray is array of objects:

[{subject1: 213123}, {subject2: 3131}]

However, body of request does not contain that array. I suspect that DELETE request is the problem, as renaming method call to e.g. PUT makes difference.

Can I allow body of DELETE request somehow?

peterh
  • 11,875
  • 18
  • 85
  • 108
onkami
  • 8,791
  • 17
  • 90
  • 176
  • Looking on github at [$resource](https://github.com/angular/angular.js/blob/master/src/ngResource/resource.js) it has `var hasBody = /^(POST|PUT|PATCH)$/i.test(action.method);` which looks like Angular doesn't include the body on `DELETE` requests intentionally... As to working round it, I don't know :( – RobH May 12 '14 at 13:14

2 Answers2

5

Take a look at this answer.

The body of a request for a DELETE is ignored. You will have to use POST to do what you want, or describe the data you are sending with the URL.

UPDATE: DELETE requests can have a body since Angular 1.6.4; check denisazevedo's answer for additional info.

Community
  • 1
  • 1
link
  • 1,676
  • 1
  • 13
  • 21
4

Starting on Angular 1.6.4, the hasBody action configuration was added.

You can now have:

deleteSomething: {
    method: 'DELETE',
    hasBody: true
}

hasBody - {boolean} - allows to specify if a request body should be included or not. If not specified only POST, PUT and PATCH requests will have a body.

Reference

Denis C de Azevedo
  • 6,276
  • 2
  • 32
  • 49