title: How to rename resources in an idempotent manner?
body: <p>I implemented an API that renames a company as follows:</p>
  
  <pre><code>PUT /companies/A
  {
    "name": "B"
  }
  </code></pre>
  
  <p>will return <code>HTTP 301</code> with the <code>Location</code> header pointing at the company's new URI: <code>/companies/B</code>.</p>
  
  <p><strong>How can I make this operation idempotent with and without <code>If-Match</code> headers?</strong></p>
  
  <ol>
  <li><p>Without <code>If-Match</code> header: if a user tries to rename a non-existent company, I'd expect the server to return <code>HTTP 404</code> but I can't do so because then legitimate rename operations wouldn't be idempotent (they'd return <code>301</code> the first time, and <code>404</code> on subsequent invocations). This is problematic because I want clients to be able to differentiate between a failed renames (the company doesn't exist) versus a rename that had already taken place.</p></li>
  <li><p>With <code>If-Match</code> header: if the company's <code>ETag</code> depends on the company name, then subsequent rename operations will fail because the precondition no longer holds. Again, this makes it seem that the operation failed when in fact it already took place.</p></li>
  </ol>