6

Below is my restangular delete request where i intend to pass an array of ids to delete based on user selection

var deleteIds = [1,5,10]
Restangular.all('url').customDELETE(deleteIds);

I want this deleteIds to be passed in body params. How can i send the array as body so tat i could see the request payload.

Alaksandar Jesus Gene
  • 6,523
  • 12
  • 52
  • 83

2 Answers2

2

Actually I also needed to use the delete http method with data passed in the body, and I found that Restangular supports a customOperation

documentation: https://github.com/mgonto/restangular#custom-methods

  • customOperation(operation, path, [params, headers, elem]): This does a custom operation to the path that we specify. This method is actually used from all the others in this subsection. Operation can be one of: get, post, put, remove, head, options, patch, trace

example:

Restangular.all('some/path/123')
    .customOperation('remove', '',{'content-type': 'application/json'},[1,5,10])
Marcelo Waisman
  • 556
  • 3
  • 11
  • params is missing in your example. it should be `Restangular.all('some/path/123') .customOperation('remove', '', null, {'content-type': 'application/json'}, [1,5,10])` (note the third parameter with value `null`) – Alp Nov 15 '19 at 09:31
0

Depending on the backend technology you use, the body might be ignored for DELETE requests. See this question for more info.

I would suggest you to pass the id's as a part of the url.

Community
  • 1
  • 1
fikkatra
  • 5,605
  • 4
  • 40
  • 66
  • Thanks for the suggestion.Actually the backend is coded and they dont want to be distrubed for multiple reasons. That's why i got struck. Any other ideas to overcome this. – Alaksandar Jesus Gene Apr 19 '16 at 15:18
  • Sending body with GET and DELETE action is not advised but still allowed. For example ElasticSearch API supports it. – mirik Dec 07 '22 at 20:16