JohnC
JohnC

Reputation: 4148

How can I define an Angular resource that doesn't use query parameters for REST GET?

Currently I have a resource defined in Angular like this:

Users: $resource(APIBASEROUTE +'/users/:_id', {_id: '@_id'})

When I call for a user with this code:

$scope.user = ayApi.Users.get({id:$routeParams.userId});

The request is sent as a query parameter like this:

http://localhost:3000/api/v1/users?id=526eff826a6100fb22000000

However it needs to hit the REST server like this:

http://localhost:3000/api/v1/users/526eff826a6100fb22000000

How do I make Angular do it this way?

Upvotes: 3

Views: 511

Answers (1)

Radim Köhler
Radim Köhler

Reputation: 123861

I guess that the problem is in incosistency of the parameters names.

in definition you have: {_id:'@_id'}), it should be the {id...

Or in your call it should be with underscore

$scope.user = ayApi.Users.get({_id:$routeParams.userId});

Any other parameter (not mapped in the resource definition) is treated as a query string param. That's why angular decided to append your id as a query string part. It is not _id

Upvotes: 2

Related Questions