Photo by Ryan Song on Unsplash
What is an Idempotency?
One can apply a certain operation on something many times, without changing the result of the operation after the first time the operation is applied.
No matter how many times you call the operation, the result will be the same.
The Funny Example about it
let?s say we have a cow it eats a mixture of grass hay, alfalfa hay, grains as well as corn and grass silage and it always gives you a milk
Idempotent REST APIs
If clients can make that same call repeatedly while producing the same result, for example :- avoid processing a transaction multiple times.
An idempotent HTTP method is a HTTP method that can be called many times without different outcomes. It would not matter if the method is called only once, or ten times over. The result should be the same.
The GET method is idempotent, as multiple calls to the GET resource will always return the same response.
The PUT method is idempotent, as calling the PUT method multiple times will update the same resource and not change the outcome.
The POST is not idempotent, and calling the POST method multiple times can have different results and will result in creating new resources.
The DELETE is idempotent because once the resource is deleted, it is gone and calling the method multiple times will not change the outcome.