Hi Folks,
I'm proposing to change the response code for idempotent v3 PUT APIs as follows:
# 201 (Resource Created) - if the resource was successfully created
# 200 (OK) - if the resource already exists, and wasn't modified
Pros:
* More accurate, since it specifies if the resource was created or it already exists
Argument: We could do that even by using 200 always, and indicating in the response message if the resource was created or it already existed
Cons:
* We say that a PUT is idempotent, meaning that the request can be issued repeatedly without changing its outcome. Now consider the situation where a PUT fails with a timeout. The client will retry, and because it is idempotent, it will expect the same response as if it were the first attempt. But depending on what happened on the server side, the response will now be either a 201, or a 200. So the client needs to be prepared for both response codes.
Argument: Even though this change would mean that the API response may not be idempotent (201 or 200), underlying, it is idempotent in the sense that repeated calls do not change the state (of the MDS in this case).
* It would be easier for clients if we returned 200 always in idempotent PUT APIs (whether or not the resource was newly created), especially since most developers are not even aware of the existence of 201, they simply expect a 200 for successful calls.
We should ensure that all APIs are consistent in this aspect. Please share your thoughts about this, since we are actively developing v3 APIs for CDAP, and if we do decide to make this change, we should make it now.
Thanks,
Bhooshan