d3514514
d3514514

Reputation: 91

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){

Upvotes: 7

Views: 19234

Answers (1)

Raphael Rafatpanah
Raphael Rafatpanah

Reputation: 19967

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);
  });

Upvotes: 7

Related Questions