Send Request Body on $resource

I take a look on Angular API for $resource and I didn't find some way to send a Request Body to a RESTful service.

I know this is possible using $http approach, like here, so, is it also possible to do using $resource ?

Apparently this is the options for $resource .

action – {string} – The name of action. This name becomes the name of the method on your resource object.

method – {string} – HTTP request method. Valid methods are: GET, POST, PUT, DELETE, and JSONP

params – {object=} – Optional set of pre-bound parameters for this action.

isArray – {boolean=} – If true then the returned object for this action is an array, see returns section.

At the moment I didn't found any way to send a request payload containing an JSON object.


As long as the action supports a body message (eg POST, but not GET), you can pass a data parameter to the action method of your resource, which will be sent in the body of the request:

yourResource.save(yourData)

Example: http://jsfiddle.net/N3NXK/1/


基于@gargc的答案,您可以将参数和主体传递给资源的方法:

myResource.save({ param: myParam }, myObject);
链接地址: http://www.djcxy.com/p/89552.html

上一篇: 将REST搜索端点映射到$资源

下一篇: 在$资源上发送请求正文