title: HTTP Status 412 (Precondition Failed) and Database Versioning
body: <p>I am implementing a RESTful web service that accesses a database.  Entities in the database are versioned to detect multiple updates.  For instance, if the current value is <code>{"name":"Bill", "comment":"tinker", "version":3}</code>, if one user PUTs <code>{"name":"Bill", "comment":"tailor", "version":3}</code>, the request will succeed (200 OK) and the new value will be <code>{"name":"Bill", "comment":"tailor", "version":4}</code>.  If a second user PUTs <code>{"name":"Bill", "comment":"sailor", "version":3"}</code> that request will fail (409 Conflict) because the version number does not match.</p>
  
  <p>There are existing non-RESTful interfaces, so the design of the databases cannot be changed.  The RESTful interface calls an existing interface that handles the details of checking the version.</p>
  
  <p>A rule of thumb in RESTful web services is to follow the details of HTTP whenever possible.  Would it be better in this case to use a conditional header in the request and return 412 Precondition Failed if the version does not match?  The appropriate header appears to be If-Match.  This header takes an ETag (Entity Tag) which could be a hash of the representation of the current state of the resource.</p>
  
  <p>If I did this, the ETags would be for appearances' sake, because the version would still be the real thing I'm testing for.</p>
  
  <p>Is there any reason I should do this, other than "making it more RESTful", whatever that is supposed to mean?</p>