title: What's the RESTful way of attaching one resource to another?
body: <p>this is one of the few moments I couldn't find the same question that I have at this place so I'm trying to describe my problem and hope to get some help an ideas!</p>
  
  <p><strong>Let's say...</strong></p>
  
  <p>I want to design a RESTful API for a domain model, that might have entities/resources like the following:</p>
  
  <pre><code>class Product
  {
      String id;
      String name;
      Price price;
      Set&lt;Tag&gt; tags;
  }
  
  
  class Price
  {
      String id;
      String currency;
      float amount;
  }
  
  
  class Tag
  {
      String id;
      String name;
  }
  </code></pre>
  
  <p>The API might look like:</p>
  
  <pre><code>GET /products
  GET /products/&lt;product-id&gt;
  PUT /prices/&lt;price-id&gt;?currency=EUR&amp;amount=12.34
  PATCH /products/&lt;product-id&gt;?name=updateOnlyName
  </code></pre>
  
  <p>When it comes to updating references:</p>
  
  <pre><code>PATCH /products/&lt;product-id&gt;?price=&lt;price-id&gt;
  PATCH /products/&lt;product-id&gt;?price=
  </code></pre>
  
  <p>may set the Products' Price-reference to another existing Price, or delete this reference.</p>
  
  <p>But how can I add a new reference of an existing Tag to a Product?</p>
  
  <p>If I wanted to store that reference in a relational database, I needed a relationship table 'products_tags' for that many-to-many-relationship, which brings us to a clear solution:</p>
  
  <pre><code>POST /product_tags [product: &lt;product-id&gt;, tag: &lt;tag-id&gt;]
  </code></pre>
  
  <p>But a document-based NoSQL database (like MongoDB) could store this as a one-to-many-relationship for each Product, so I don't need to model a 'new resource' that has to be created to save a relationship.</p>
  
  <p>But</p>
  
  <pre><code>POST /products/&lt;product-id&gt;/tags/ [name: ...]
      creates a new Tag (in a Product),
  
  PUT /products/&lt;product-id&gt;/tags/&lt;tag-id&gt;?name=
      creates a new Tag with &lt;tag-id&gt; or replaces an existing 
      Tag with the same id (in a Product),
  
  PATCH /products/&lt;product-id&gt;?tags=&lt;tag-id&gt;
      sets the Tag-list and doesn't add a new Tag, and
  
  PATCH /products/&lt;product-id&gt;/tags/&lt;tag-id&gt;?name=... 
      sets a certain attribute of a Tag.
  </code></pre>
  
  <p>So I might want to say something link this: </p>
  
  <pre><code>ATTACH /products/&lt;product-id&gt;?tags=&lt;tag-id&gt;
  ATTACH /products/&lt;product-id&gt;/tags?tag=&lt;tag-id&gt;
  </code></pre>
  
  <p><strong>So the point is:</strong></p>
  
  <p>I don't want to create a new resource,</p>
  
  <p>I don't want to set the attribute of a resource, but</p>
  
  <p>I want to ADD a resource to another resources attribute, which is a set. ^^</p>
  
  <p><strong>Since everything is about resources, one could say:</strong></p>
  
  <p>I want to ATTACH a resource to another.</p>
  
  <p>My question: <strong>Which Method is the right one and how should the URL look like?</strong></p>