What title says - if I have an endpoint to create element, but the element already exist, what's the best / common practice? Should I:
- Return conflict based on the fact that an object with the key already exist?
- Or check if the existing object is the same, and if so return 200 instead (or other ok-ish status code)?
Thanks!
There is relevant content in RFC 9110, section 13.1.1
Returning a successful response when the server action was a no-op is fine.
But you certainly aren't required to do that - it's also fine to send an error response to the client indicating that their local view of the world is out of date.
"Best" practice, presumably, is to sit down and do the math - what's the cost of each implementation? how frequently does it come up? what are the benefits? How much of the cost is pushed back onto the consumers of the API, and is that consistent with the targets we need to meet to get adoption, and so on.