This is my first question so don't burn me at stake.
I have an API that I'm sending GET,POST,PUT,DELETE requests to using $resource. I have managed to make a GET and a POST request that do what they're supposed to, but whenever I try to send a PUT request I get a 404 error and an OPTIONS method sent instead.
Basically, my PUT request should be sent with same parameters that the POST has. When I send the seemingly same request over Postman extension, it works fine. I just have no idea how to replicate it via $resource.
plunker with issue: http://plnkr.co/edit/gJV4otD0XGKoQWOq3PdK (it's much more clear on plunkr than on this pasted piece of code by the way)
services.js
angular.module('starter.services',['ngResource']).factory('RESTCalls', function ($resource) {
return $resource('http://api.artistappz.com/api/v1/news/:urlkey/:id/x-app-id/3865f620590f40d493ec8d900b4c24d3/', null, {
update: {
method:'PUT'
},
save: {
method:'POST',
headers:{
'Content-Type':'application/x-www-form-urlencoded'
}
}
});
});
controllers.js
angular.module('starter.controllers',[]).controller('HomeController', ['$scope','RESTCalls', function ($scope, RESTCalls) {
$scope.RESTGet = function() {
RESTCalls.get(function (response) {
console.log(response);
});
};
$scope.RESTPost = function() {
RESTCalls.save('user_id=76A5FC91E4684FA1ACB2FDA645FD5B2C&title=dejan seme ti jebem krvavo&body=dejan&url=dejanurl',function(response) {
console.log('SUCCESS:');
console.log(response);
},function (responseerr) {
console.log('ERROR:');
console.log(responseerr);
});
};
$scope.RESTPut = function() {
///item/84173EF7D6FD4469B411057C72F53DE2
RESTCalls.get({urlkey:'item',id:'84173EF7D6FD4469B411057C72F53DE2'},function (response) {
var tempobject = response.data.news['84173EF7D6FD4469B411057C72F53DE2'];
tempobject.user_id = '76A5FC91E4684FA1ACB2FDA645FD5B2C';
RESTCalls.update({urlkey:'item',id:'84173EF7D6FD4469B411057C72F53DE2'},tempobject);
});
};}]);
postman PUT request https://i.stack.imgur.com/zLMUA.jpg