One-To-Many Association REST API
<p>We have a bit ambiguity problem here with the API design, specially with one to many association.</p>

<p><strong>Scenario:</strong></p>

<blockquote>
  <p>Student – Has many – Books (one to many)</p>
</blockquote>

<p>How should the API look to assign books to <code>student</code>? Expected behaviour is to remove some from existing and add new to existing.</p>

<p><code>[POST] /students/1234/books</code> -  Not Allowed (As books can be assigned to other users later. May be suitable for a support ticket and comment scenario)</p>

<p><code>[PUT] /students/1234/books</code>  –  From a pragmatic REST API point of view, it is the modification of the collection than an entity inside the collection.</p>

<p><strong>Existing Student Books :</strong> <code>[{id:1, name:’REST1’, author:’Satish’, year:2003}, {id:2, name:’REST2’, author:’Satish’ , year:2003}]</code></p>

<p><strong>Modified Student Books :</strong> <code>[{id:2, name:’REST2’, author:’Satish’ , year:2003}, {id:3, name:’REST3’, author:’Satish’ , year:2003}]</code> – one removed and one new added.</p>

<p>Now this functionality could have been best achieved by only sending the list of book ids as shown below. But that would more be an action than resource oriented. On the other side sending the list of book objects for mapping would be quite heavy for mobile clients looks at the bandwidth available.</p>

<p><strong>Request Payload :</strong> <code>[1, 2, 4]</code> </p>

<p>Is there a practice adapted in industry for such problems?</p>