title: RESTful API design - how to handle foreign keys?
body: <p>I'm designing a RESTful API and I'm trying to figure out how to show and update foreign keys for resources.</p>
  
  <p>Let's I have an object User and it has an id, name and a foreign key (many-to-one relation) to entity: Computer.</p>
  
  <p>What I see in most of the examples online:</p>
  
  <p><strong>GET /users/1</strong></p>
  
  <pre><code>{
    id: 1,
    name: "Bob",  
    computer: "&lt;url&gt;/computers/5"
  }
  </code></pre>
  
  <p>Which I can understand, it's a link to another resource. But what do you do when you want to pick another computer for bob?</p>
  
  <p><strong>PUT /users/1</strong></p>
  
  <pre><code>{
    name: "Bob",
    computer: "&lt;url&gt;/computers/4"
  }
  </code></pre>
  
  <p>This feels really weird. 
  I'm also thinking about the following case: Say the person that has to implement the API can choose a computer for Bob using a dropdown and the current one should be selected, I'd need the id to do that. Do I have to parse the url myself to chop off the id?</p>
  
  <p>Is there a reason why I should not just do:</p>
  
  <p><strong>GET /users/1</strong></p>
  
  <pre><code>{
    id: 1,
    name: "Bob",  
    computerId: 5
  }
  </code></pre>
  
  <p><strong>PUT /users/1</strong></p>
  
  <pre><code>{
    name: "Bob",
    computerId: 4
  }
  </code></pre>