角资源自定义URL是使用查询字符串和POST参数 [英] Angular resource custom URL is using query strings and POST parameters

查看:196
本文介绍了角资源自定义URL是使用查询字符串和POST参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经写在一个角资源自定义方法在我的应用程序激活用户。该API端点 /用户/激活和激活code必须是PUTed这个端点。这是我的资源是什么样子:

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});

正如你可以在Chrome网络日志中看到,激活code被查询字符串和请求体发送:

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

我怎样才能改变资源只是通过激活code在请求主体,而不是在查询字符串?

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

推荐答案

只是删除​​ PARAMS 从动作声明:

Just remove params from the action declaration:

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

这篇关于角资源自定义URL是使用查询字符串和POST参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆