I implemented the REST / CRUD backend, following this article as an example: http://coenraets.org/blog/2012/10/creating-a-rest-api-using-node-js-express-and-mongodb/ . My MongoDB works locally, I do not use MongoLabs.
I followed a Google tutorial that uses the ngResource and Factory template, and I have a request (GET all elements), get an element (GET), create an element (POST) and delete the element (DELETE) at work. I am having difficulty implementing PUT as required by the API: PUT for the URL, which includes the identifier (... / foo /), and also includes updated data.
I have this bit of code to define my services:
angular.module('realmenServices', ['ngResource']). factory('RealMen', function($resource){ return $resource('http://localhost\\:3000/realmen/:entryId', {}, { query: {method:'GET', params:{entryId:''}, isArray:true}, post: {method:'POST'}, update: {method:'PUT'}, remove: {method:'DELETE'} });
I call the method from this controller code:
$scope.change = function() { RealMen.update({entryId: $scope.entryId}, function() { $location.path('/'); }); }
but when I call the update function, the URL does not include the ID value: it is only "/ realmen", not "/ realmen / ID".
I tried various solutions related to adding "RealMen.prototype.update", but still can't get entryId to display at the url. (It seems that I will have to build JSON, saving only the values ββof the database fields - the POST operation does this for me automatically when creating a new record, but there does not seem to be a data structure that contains only the field values ββwhen I view / edit one record) .
Is there an example client application that uses all four verbs in the expected RESTful path?
I also saw links to Restangular and another solution that overrides $ save so that it can issue POST or PUT ( http://kirkbushell.me/angular-js-using-ng-resource-in-a-more-restful-manner / ). This technology seems to be changing so fast that there seems to be no good reference solution that people can use as an example.