I know that PUT is idempotent but how Can I ensure it programatically? What conditions I must meet to create fully idempotent endpoint ?
-
Do you really mean _idempotent_ or do you mean _safe_ (side effect free)? Idempotent just means that you get the same result if you invoke a _PUT_ on a resource. You just replace the content of the resource by the new content, the result should alway be (for example) an HTTP Status Code 200 (as long as the resource exists). – andih Aug 04 '17 at 07:56
1 Answers
From a RESTful service standpoint, for an operation (or service call) to be idempotent, clients can make that same call repeatedly while producing the same result. In other words, making multiple identical requests has the same effect as making a single request. Note that while idempotent operations produce the same result on the server (no side effects), the response itself may not be the same (e.g. a resource's state may change between requests).
A PUT
is supposed to update a resource with new values received in the request body. Therefore, whether it's sent just once or a couple of times, the result on the server shouldn't change (unlike a POST
, for example, where more requests will result in either a conflict error or in multiple resources created).

- 5,569
- 6
- 34
- 50
-
1You have to take care there is a difference between _idempotent_ and _safe_. _Idempotent_ means you can call the same method as often as you want and you'll get the same result, it does not mean that the resource will not be modified. Best example is the _delete_ method/http verb. _POST_ and _PATHCH_ are neither _idempotent_ nor _safe_ while _PUT_ and _DELETE_ are _idempotent_ but *not* _safe_. – andih Aug 04 '17 at 07:53