Why is delete idempotent
Idempotence is a funky word that often hooks people. Idempotence is sometimes a confusing concept, at least from the academic definition. 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.
It would not matter if the method is called only once, or ten times over. The result should be the same. For example, if we make the PUT request from our test once, it updates the avatarNumber to 2.
If we make it again, the avatarNumber will still be 2. If we make the PUT request 1 time or 10 times, the server always results in the same state.
All safe methods are also idempotent, but not all idempotent methods are safe. Even if safe methods have a read-only semantic, servers can alter their state: e. Post method always results in a server state change. If the POST method was idempotent , everything sent and accepted to or from the web server would already have to exist on the server in some form to respond with the same codes and value response.
For that reason, POST cannot be idempotent. Such a request can be done before deciding to download a large resource to save bandwidth, for example. A response to a HEAD method should not have a body.
The difference between POST and PUT is that PUT is idempotent, that means, calling the same PUT request multiple times will always produce the same result that is no side effect , while on the other hand, calling a POST request repeatedly may have additional side effects of creating the same resource multiple times.
An idempotency key is a unique value that's generated by a client and sent to an API along with a request. The server stores the key to use for bookkeeping the status of that request on its end. We have to make our APIs fault-tolerant in such a way that the duplicate requests do not leave the system unstable. An idempotent HTTP method is a method that can be invoked many times without the different outcomes.
It should not matter if the method has been called only once, or ten times over. The result should always be the same. Idempotency essentially means that the result of a successfully performed request is independent of the number of times it is executed. So, POST is not idempotent. They are purely for retrieving the resource representation or metadata at that point in time.
If you invoke a PUT API N times, the very first request will update the resource; the other N-1 requests will just overwrite the same resource state again and again — effectively not changing anything. Clearly, the response is different from the first request, but there is no change of state for any resource on the server-side because the original resource is already deleted.
Rfc SO Thread. PATCH is missing. Of course this depends on the implementation. But it would be valid. When we send a POST request, it will create a new resource. Now if we resend identical POST request N times, conflict error would be returned as an identical record already exists. Improve this answer. It may be "server state" or it may be response sent to client. PauloMerson Thanks, personally I don't think it matters whether the second return is or , the state of the server hasn't changed so I'm happy with that.
Bruno Bruno k 26 26 gold badges silver badges bronze badges. Janac Meena Janac Meena 2, 22 22 silver badges 26 26 bronze badges. Community Bot 1 1 1 silver badge. RayLuo RayLuo Note that's "side effects", not "response". Regardless of the response code. Quote from another comment : Computing idempotence is about the robustness of a system.
Franklin Yu Franklin Yu 6, 4 4 gold badges 38 38 silver badges 48 48 bronze badges. Suppose we have to manage football teams represented by id, name, city. It is obvious that GET requests are idempotent also. I think the same thing, - Account doesn't exist. To generate a you would have to know that the object used to exist, which is very un-restful.
Bruno - I'm aware of what it means, the OP cited it. I think would be fine. You want the state of the server to be that the account is gone.
Does it matter which request actually made it go away? It's still gone on the second request, server state hasn't changed. Sign up or log in Sign up using Google. Sign up using Facebook.
Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Does ES6 make JavaScript frameworks obsolete? Podcast Do polyglots have an edge when it comes to mastering programming Featured on Meta. Now live: A fully responsive profile.
0コメント