title: Rest api design: POST to create with duplicate data, would-be IntegrityError/500, what would be correct?
body: <p>I have a normal, basic REST api like:</p>
  
  <pre><code>/
      GET - list
      POST - create
  
  /&lt;id&gt;
      GET - detail
      PUT - replace
      PATCH - patch
      DELETE - delete
  </code></pre>
  
  <p>When a POST comes in to <code>/</code>, I usually create an object and make a new id. Some (one) of the fields are (is) required to be unique. So, a POST with such duplicate data could result in:</p>
  
  <ol>
  <li>500 - IntegrityError</li>
  <li>Make it more like a <code>PUT</code>/<code>PATCH</code> to <code>/&lt;id&gt;</code> and update the existing record</li>
  <li>Catch/avoid the error and return some sort of <code>4XX</code></li>
  <li>Something else I'm not thinking of.</li>
  </ol>
  
  <p><code>1</code> seems out: the request is either bad or I can deal with it. What is the correct way to handle this situation? </p>