What is idempotency?
What is idempotency?
If an operation, or a service call, is idempotent, "clients can make the same call repeatedly while producing the same result." Note that in software development when we talk about the client, we talk about the hardware or the software device that makes the request to the server. Therefore, "making multiple identical requests has the same effect as making a single request." Source.
The PUT method is RESTful APIs is defined as being idempotent. If I create an item with a primary key, I cannot create a new item with the same primary key again; however, if you use the same PK with a bit request and with different info then you will end up updating it. Nevertheless, if you put (...) through the same PUT request with the same info then it will not be modified, and that is exactly what you want. Technically DELETE is idempotent too.
There is a caveat with DELETE - because you can only DELETE once - the outcome is the same on every call - the item is not there any longer. However you might receive different response codes from the server (404 instead of 200 or 204) because the request can no longer be fulfilled. You cannot delete an item which has already been deleted.
GET is also idempotent. GET should never be used to retrieve data. HTTP refers to GET as a safe method. The data returned should always be the same (unless it has been altered in another place).
Comments
Post a Comment