Using Spring Data REST with Angular’s $resource object is very useful and convenient, but I’ve faced a problem with CRUD update. First you need to create such method while creating $resource object:
angular.module('myApp.services',[]).factory('Something',function($resource){
return $resource('http://giveMeSomeRest.nom/please/:id',{id:'@_id'},{
update: {
method: 'PUT'
}
});
});
But when this method was called I got 405 Method Not Allowed
error. The problem is Spring expects to have an id in the URL. To add it modify creation of a $resource object:
angular.module('myApp.services',[]).factory('Something',function($resource){
return $resource('http://giveMeSomeRest.nom/please/:id',{id:'@_id'},{
update: {
method: 'PUT',
params: {id: "@id"},
}
});
});
Please note that @id
refers to the parameter defined above, so no underscore is needed.