3

This is how I use Angular's $http.get to send parameters to a REST endpoint. It works:

var httpParams = {'myparam1': 'Hello'};
$http.get('http://localhost:8976/my/url', {'params': httpParams}).then(successFunc, failureFunc);

This sends a GET call that is equivalent to the following CURL command:

curl --request GET "http://localhost:8976/my/url?myparam1=Hello"

But now want to send a DELETE request with the same URL and the same parameters. How do I do it? This doesn't work:

var httpParams = {'myparam1': 'Hello'};
$http.delete('http://localhost:8976/my/url', {'params': httpParams}).then(successFunc, failureFunc);

The URL gets hit, but the parameters are not received by the REST endpoint.

7
  • $http.delete("http://localhost:8976/my/url?" + httpParams) Commented Oct 21, 2016 at 11:08
  • Sorry, Sravan, that isn't correct. You cannot concatenate an object and a string like that. Commented Oct 21, 2016 at 11:14
  • 1
    var httpParams = $.param({ 'myparam1': 'Hello' });, use $.param to convert it into query params. Commented Oct 21, 2016 at 11:17
  • checked with that? Commented Oct 21, 2016 at 11:27
  • Hmm, that is odd. What backend are you using to serve up your endpoints? Can you confirm in the client dev tools that the request contains the query parameters in the URL? Commented Oct 21, 2016 at 11:34

1 Answer 1

1

For handling RESTful things you should use Angular#$resource which provide delete method on each resource object.And you can configure the params as well during resource configuration and creation.

Using resource,you can have CRUD API without manual configuration. so,http GET,POST,DELET,PUT method on this resource object

If you want to send DELETE REST manually then better pass the parameter as query string.It does not send the parameter in the body.

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.