7

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){
1
  • I think you need more context around the problem. Commented Jan 22, 2017 at 17:21

1 Answer 1

7

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);
  });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.