Send Request Body on $resource

Deividi Cavarzan picture Deividi Cavarzan · Apr 25, 2013 · Viewed 48.4k times · Source

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.

Answer

Pier-Luc Gendreau picture Pier-Luc Gendreau · Jul 19, 2014

Building on @gargc's answer, you can pass parameters and a body to a resource's method:

myResource.save({ param: myParam }, myObject);