Angular resource custom URL is using query strings and POST parameters

徘徊边缘 提交于 2019-12-09 16:49:10

问题


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:

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


回答1:


Just remove params from the action declaration:

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


来源:https://stackoverflow.com/questions/23528512/angular-resource-custom-url-is-using-query-strings-and-post-parameters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!