title: AngularJS best practice REST / CRUD
body: <p>What is the best practice of doing CRUD operations via REST with AngularJS? </p>
  
  <p>Specially what is the <strong>Angular-Way</strong> here. By this I mean the way using the <strong>least code</strong> and the <strong>most default angular settings</strong> to achive this.</p>
  
  <p>I know $resource and it's default operations. Where I'm not sure is how to implement/name the endpoints and which controllers to use.</p>
  
  <p>For this example I would like to implement a simple user-management system which creates / updates /deletes / lists users. Since I'm implementing the Server-Endpoints by myself I'm completely free in doing it in the most angular friendly way.</p>
  
  <p>What I like as answer is something like:</p>
  
  <p><strong>Server-Endpoints:</strong></p>
  
  <pre><code>GET /service/users -&gt; array of users
  GET /service/user/new -&gt; return an empty user with default values which has no id
  POST /service/user/new -&gt; store a new user and create an id. return the saved user.
  POST /service/user/:ID -&gt; save an existing user. Return the saved user
  DELETE /service/user/:ID -&gt; delete an existing user
  </code></pre>
  
  <p><strong>Angular-Services:</strong></p>
  
  <pre><code>.factory( 'User', [ '$resource', function( $resource ){
  
      return $resource( '/service/user/:userId', { userId: '@id' } )
      [...]
  
  }])
  </code></pre>
  
  <p><strong>Routing:</strong></p>
  
  <pre><code>.when( '/users', {
      templateUrl: BASE + 'partials/user-list.html',
      controller: 'UserListCtrl' } )
  
  .when( '/user/new', {
      templateUrl: BASE + 'partials/user-edit.html',
      controller: 'UserNewCtrl' } )
  
  .when( '/user/:userId', {
      templateUrl: BASE + 'partials/user-edit.html',
      controller: 'UserEditCtrl' } )
  ...
  </code></pre>
  
  <p><strong>Controllers:</strong></p>
  
  <pre><code>UserListCtrl:
  
      $scope.data = User.get(...)
  
  UserNewCtrl:
  
      $scope.user = User.get( { userId: "new" } )
  
  ...
  </code></pre>
  
  <p>Note that I'm not interessted in opinion what is the <em>best</em> (tm) way to do this but I'd like to know what is the <strong>Angular intended</strong> way (which I think should produce the least code because it can use the most default).</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I'm looking for <em>the whole picture</em>. What I would love would be an answer like e.g.: "You can do this using online 3 Endpoints [...], 2 routes [...] and 2 controllers [...] if you do it <em>this</em> way using <em>that</em> defaults ..."</p>