3

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?

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

Doh! Thank you so much for your sharp eyes!, this has been vexing me for some time. Glad it was such a silly mistake and not some weirdness in Angular to be dealt with.

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.