I implemented an API that renames a company as follows:
PUT /companies/A
{
"name": "B"
}
will return HTTP 301
with the Location
header pointing at the company's new URI: /companies/B
.
How can I make this operation idempotent with and without If-Match
headers?
Without
If-Match
header: if a user tries to rename a non-existent company, I'd expect the server to returnHTTP 404
but I can't do so because then legitimate rename operations wouldn't be idempotent (they'd return301
the first time, and404
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.With
If-Match
header: if the company'sETag
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.