Idempotency For Dummies

Idempotency For Dummies

Image for postPhoto 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

Image for post

Idempotent REST APIs

If clients can make that same call repeatedly while producing the same result, for example :- avoid processing a transaction multiple times.

Idempotent methods

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.

Examples

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.

References :

  • https://tools.ietf.org/html/rfc7231#section-4.2.2
  • https://restfulapi.net/idempotent-rest-apis/
  • https://ieftimov.com/understand-how-why-add-idempotent-requests-api
  • https://stackoverflow.com/questions/1077412/what-is-an-idempotent-operation
1

No Responses

Write a response