Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass multiple parameters in HTTP DELETE request

I want to pass the id and dept field in a DELETE HTTP request and fetch inside deleteData() but I'm receiving null in deleteData() for id and dept.

$http['delete']('webapi/Data/delete?' + cdata.id + "&&" + cdata.lineUp)

@DELETE()
@Path("/delete")
public String deleteData(@QueryParam("id") String id, @QueryParam("dept") String dept){
like image 544
d3514514 Avatar asked Jan 22 '17 15:01

d3514514


1 Answers

HTTP Delete does not accept data as an argument.

Won't Work

Otherwise, I would pass an object like so:

var cdata = {
   id: 2,
   lineUp: [...]
};

// won't work
$http.delete('webapi/Data/delete, cdata)
  .then(function(response) {
     console.log(response);
  })
  .then(function(error) {
     console.log(error);
  });

If you wanted to be truly RESTful, you shouldn't need to pass anything to the HTTP Delete method besides the id.

RESTFul

var cdata = {
   id: 2,
   lineUp: [...]
};

// RESTful
$http.delete('webapi/Data/delete/' + cdata.id)
  .then(function(response) {
     console.log(response);
  })
  .then(function(error) {
     console.log(error);
  });

You can, however, use HTTP Post as a workaround.

Workaround

var cdata = {
   id: 2,
   lineUp: [...]
};

// workaround
$http.post('webapi/Data/delete, cdata)
  .then(function(response) {
     console.log(response);
  })
  .then(function(error) {
     console.log(error);
  });
like image 197
Raphael Rafatpanah Avatar answered Sep 21 '22 15:09

Raphael Rafatpanah