Angular Resource custom URL uses query strings and POST parameters

I wrote a custom method on an Angular resource in my application to activate the user. The API endpoint is /users/activate , and the activation code must be set 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 use it in my controller as follows:

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

As you can see from the weblog in Chrome, the activation code is sent to the query string and the request body:

enter image description here

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

+7
javascript angularjs rest put api
source share
1 answer

Just remove params from the action declaration:

 activate: {method:'PUT', url: 'http://api.site.dev/users/activate'} 
+10
source share

All Articles