Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular resource custom URL is using query strings and POST parameters

I've written a custom method on an Angular resource in my application for activating a user. The API endpoint is /users/activate and an activation code must be PUTed to this endpoint. This is what my resource looks like:

app.factory('User', ['$resource',
    function($resource){
        return $resource('http://api.site.dev/users/:id', {id: '@id'}, {
            activate: {method:'PUT', params:{code: '@code'}, url: 'http://api.site.dev/users/activate'}
        });
    }]);

and I'm using it in my controller like so:

User.activate({code: $routeParams.code});

As you can see from the network log on Chrome, the activation code is being sent in the query string and request body:

enter image description here

How can I change the resource to just pass the activation code in the request body and not in the query string?

like image 824
John Dorean Avatar asked May 07 '14 21:05

John Dorean


1 Answers

Just remove params from the action declaration:

activate: {method:'PUT', url: 'http://api.site.dev/users/activate'}
like image 155
wachme Avatar answered Oct 27 '22 23:10

wachme