title: REST: Prevent creation of duplicate resources via conditional POST?
body: <p>I've been searching for best practices for preventing the accidental creation of duplicate resources when using POST to create a new resource, for the case where the resource is to be named by the server and hence PUT can't be used.  The API I'm building will be used by mobile clients, and the situation I'm concerned about is when the client gets disconnected after submitting the POST request but before getting the response.  I found <a href="https://stackoverflow.com/questions/15159274/avoid-duplicate-posts-with-rest">this question</a>, but there was no mention of using a conditional POST, hence my question.</p>
  
  <p>Is doing a conditional POST to the parent resource, analogous to using a conditional PUT to modify a resource, a reasonable solution to this problem?  If not, why not?</p>
  
  <p>The client/server interaction would be just like with a conditional PUT:</p>
  
  <ol>
  <li><p>Client GETs the parent resource, including the ETag reflecting its current state (which would include its subordinate resources),</p></li>
  <li><p>Client does a conditional POST to the parent resource (includes the parent's ETag value in an If-Match header) to create a new resource, </p></li>
  <li><p>Client gets disconnected before getting the server response, so doesn't know if it succeeded,</p></li>
  <li><p>Later, when reconnected, the client resubmits the same conditional POST request,</p></li>
  <li><p>Either the earlier request didn't reach the server, so the server creates the resource and replies with a 201, or the earlier request did reach the server, so the server replies with a 412 and the duplicate resource isn't created.</p></li>
  </ol>