Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send parameters with Angular's $http.delete()?

Tags:

rest

angularjs

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.

like image 709
Saqib Ali Avatar asked Jul 11 '26 17:07

Saqib Ali


1 Answers

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.

like image 170
RIYAJ KHAN Avatar answered Jul 13 '26 19:07

RIYAJ KHAN



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!