Saqib Ali
Saqib Ali

Reputation: 12585

How to see the HTTP request that AngularJS is sending?

I have a REST endpoint called myEndpoint that I can successfully hit using Curl like this:

curl \
--request DELETE \
--header "Content-Type: application/json" \
--header "Authorization: JWT eyJhbFciOiJ__FAKE__sInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InNhcWliIi__FAKE__9pZCI6NSwiZW1haWwiOiJzYXFpYi5hbGkuNzVAZ21haWwuY29tIiwiZXhwIjoxNDkxNzkyMzEzfQ.feGiXm__FAKE__ZS6V-OROM7EzekRzpu_5pwi865tz8" \
--data '{
    "myAttribute": "Something"
}' \
"http://localhost:3999/api/myEndpoint"

However, when my AngularJS code tries to call the same endpoint it fails saying that the mandatory myAttribute parameter was not provided. This is how angularJS is making the call:

  var httpParams = {'myAttribute': 'Something'};
  $scope.myPromise = $http.delete('http://localhost:3999/api/myEndpoint', httpParams).then(self.myEndpointSuccess, self.myEndpointFailure);

(AngularJS's attachment of the JWT token to the HTTP request is not shown, but I'm sure that is working)

How can I see exactly what HTTP request AngularJS is sending so that I can do an apples-to-apples comparison agains my working curl call?

Here is my Chrome's Developerenter image description here Tools -> Network tab. I don't see the information I'm seeking there:

Upvotes: 0

Views: 562

Answers (3)

awquadros
awquadros

Reputation: 529

The $ http service documentation says that $ http.delete gets two parameters, URL and config. By its call curl, I understand that myAtribute is the name given to a parameter that you want to send to the endpoint, in which case it should be in the params property or data property of the config object.

angular reference another question

Upvotes: 1

Matt
Matt

Reputation: 879

AngularJS provides the $http module for http requests. You can make a specific request with this module and then process the request with the . then() whichever takes a success callback followed by a error callback

Upvotes: 0

Phil
Phil

Reputation: 164834

FYI, DELETE requests do not typically have a request body.

As for your issue, RTFM; the second arg to $http.delete should be a config object, so in your case

$http.delete('http://localhost:3999/api/myEndpoint', {data: httpParams})

Upvotes: 0

Related Questions