title: RESTful url of classes with collections?
body: <p>I'm implementing a webapp and would like to comply with RESTfull design standarts, my question is.</p>
  
  <p>Given a class with a collection.</p>
  
  <p>Person {
      id   :: integer
      name :: string
      friends :: collection of Persons
  }</p>
  
  <p>What would be the 'most' correct way to implement the Person-class's interface:</p>
  
  <p>1.</p>
  
  <pre><code>example.com/REST/persons -&gt; [... {id: '2', name: 'Pete', friends: [1,4,6]} ... ]
  example.com/REST/persons/2 -&gt; {id: '2', name: 'Pete', friends: [1,4,6]}
  </code></pre>
  
  <p>Where the friends are to be looked up by using some search function on the persons class?</p>
  
  <p><strong>or</strong></p>
  
  <p>2.</p>
  
  <pre><code>example.com/REST/persons -&gt; [... {id: '2', name: 'Pete'} ... ]
  example.com/REST/persons/2 -&gt; {id: '2', name: 'Pete'}
  example.com/REST/persons/2/friends -&gt; [{id: '1', name: 'Joann'}, 
                                         {id: '4', name: 'Jim'},
                                         {id: '6', name: 'Charlie'}]
  </code></pre>
  
  <p>Where the elements in the collection are looked up as a field in the person instance.</p>
  
  <p>I've seen both things implemented, but I would like to comply with the standarts. </p>
  
  <p>a thirth way was just surgested to me.</p>
  
  <pre><code>example.com/REST/persons/2 -&gt; {id     : '2', 
                                 name   : 'Pete', 
                                 friends: [example.com/REST/person/1,
                                           example.com/REST/person/4,
                                           example.com/REST/person/6]}
  </code></pre>
  
  <p>hence making the interface event more RESTfull -- the client can now traverse the entire interface without knowing anything about the implementation.</p>
  
  <p>I hope there is some input somewhere out there.</p>