0

I'm should to send a PUT query for some url. But rest reject my query if it contains any body(JSON, like {"id": 1}). When I'm use ngResource instead of $http, query already contains a body. How can I remove it?

Sample of expected url:

http://some.com/rest/some/1/smth?method=start

Url contains :id param and thats why my factory looks like this:

.factory('ApiResourceFactory', ['$resource', function ($resource) {
        return {
            payment: $resource('http://some.com/rest/some/:id/smth',
                {orderId: '@id'},
                {
                    start: {method: "PUT", 'params': {'method': "start"}},
                    //...
                }
            )
         }
}])

Thats how I use it:

var id = 1;
ApiResourceFactory.payment.start({id: id}, function () {
    //on success
}, function (responce) {
    //on error
});

The problem is: The "id" param sends not only in url, but in request body too (request payload) as {"id": 1}.

Without body (when I'm use $http, for example), query success, but wit body server rejects my query.

So. How can I tell ngResource clear or do not fill the body?

S Panfilov
  • 16,641
  • 17
  • 74
  • 96

1 Answers1

1

Angular documentation of $resource is not very good, but if you look at the last example on the documentation you would get your answer. See section "Creating a custom 'PUT' request "

The way you have setup params is not correct. If you use @ then the parameter matching happens from body content. You do not need to provide params object. Also the call to start method is also slightly different.

See my fiddle here http://jsfiddle.net/cmyworld/wLQnq/

Chandermani
  • 42,589
  • 12
  • 85
  • 88