title: REST : Return complex nested data vs. multiple calls
body: <p>I have a REST api served by NodeJS to an AngularJS fronts.</p>
  
  <p>I work with <code>users</code> :</p>
  
  <pre><code>GET  /api/users  #Returns all users
  POST /api/users  #Create  new user
  
  GET   /api/users/:id   #Return a user
  PUT   /api/users/:id   #Edit a user
  DELTE /api/users/:id   #Delete a user
  </code></pre>
  
  <p>This is a user :</p>
  
  <pre><code>{
    login : "admin"
    email : "admin@admin.com"
    pass  : "hashedpassword"
    ...
  }
  </code></pre>
  
  <p>My user can belong to <code>groups</code> </p>
  
  <pre><code>GET   /api/users/:id/groups   #Return the groups of a user
  </code></pre>
  
  <p>They can also have <code>constraints</code> or can inherits <code>constraints</code> form their groups</p>
  
  <pre><code>GET   /api/users/:id/constraints   #Return the constraints of a user
  GET   /api/groups/:id/constraints   #Return the constraints of a group
  </code></pre>
  
  <p><strong>The problem :</strong></p>
  
  <p>I'm making an admin page, displaying All the users, their groups, their constraints.</p>
  
  <p>Should I :</p>
  
  <ol>
  <li><strong>Make many requests in a <em>for loop</em> in the javascript (Angular) front ?</strong></li>
  </ol>
  
  <p>Something like :</p>
  
  <pre><code>$http.get(/api/users).then(function(result) {
    result.data.forEach(function(user) {
      $http.get('/api/users/'+user.data.id+'/groups).then(function(groups) {
        groups.forEach(function(group) {
          $http.get('/api/groups/'+group.data.id+'/constraints)
        })
      })
    })
  })
  </code></pre>
  
  <ol start="2">
  <li><strong>Create a path <code>/api/users/withConstraintsAndGroups</code></strong></li>
  </ol>
  
  <p>That would return a big list of all the users with their groups and their constraints.</p>
  
  <hr>
  
  <p>I find solution <strong>1</strong> to be very nice, maintenable, easy, and generic but I'm affraid of very bad performance</p>
  
  <p>I find solution <strong>2</strong> to be ugly, hard to maintain, hard to code, not generic but with good performance</p>
  
  <p>Which solution should I choose?</p>