title: Angular JS: Full example of GET/POST/DELETE/PUT client for a REST/CRUD backend?
body: <p>I've implemented a REST/CRUD backend by following this article as an example: <a href="http://coenraets.org/blog/2012/10/creating-a-rest-api-using-node-js-express-and-mongodb/" rel="noreferrer">http://coenraets.org/blog/2012/10/creating-a-rest-api-using-node-js-express-and-mongodb/</a> . I have MongoDB running locally, I'm not using MongoLabs.</p>
  
  <p>I've followed the Google tutorial that uses ngResource and a Factory pattern and I have query (GET all items), get an item (GET), create an item (POST), and delete an item (DELETE) working.  I'm having difficulty implementing PUT the way the backend API wants it -- a PUT to a URL that includes the id (.../foo/) and also includes the updated data.</p>
  
  <p>I have this bit of code to define my services:</p>
  
  <pre><code>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'}
      });
  </code></pre>
  
  <p>I call the method from this controller code:</p>
  
  <pre><code>$scope.change = function() {
      RealMen.update({entryId: $scope.entryId}, function() {
              $location.path('/');
      });
  }
  </code></pre>
  
  <p>but when I call the update function, the URL does not include the ID value: it's only "/realmen", not "/realmen/ID".</p>
  
  <p>I've tried various solutions involving adding a "RealMen.prototype.update", but still cannot get the entryId to show up on the URL.  (It also looks like I'll have to build the JSON holding just the DB field values myself -- the POST operation does it for me automatically when creating a new entry, but there doesn't seem to be a data structure that only contains the field values when I'm viewing/editing a single entry).</p>
  
  <p>Is there an example client app that uses all four verbs in the expected RESTful way?</p>
  
  <p>I've also seen references to Restangular and another solution that overrides $save so that it can issue either a POST or PUT (<a href="http://kirkbushell.me/angular-js-using-ng-resource-in-a-more-restful-manner/" rel="noreferrer">http://kirkbushell.me/angular-js-using-ng-resource-in-a-more-restful-manner/</a>).  This technology seems to be changing so rapidly that there doesn't seem to be a good reference solution that folks can use as an example.</p>