On the idempotency of GET

I read about the GET HTTP method and, in particular, about its idempotent quality.

This is my understanding: if I call the GET operation 1 time or a million times (or any number of times), the result should be the same.

My problem with this definition is this. Imagine if I have a movie database and I perform a GET operation in which I return all the James Bond movies to the database.
Imagine that I run this request a million times, and after 500,000 times someone else starts a POST request in the database, adding a new Bond movie.
Well, now half of the GET operations returns N results, and the other half returns N + 1 results.

Does this not violate idempotency, as is usually described?
Wouldn't it be better if the idempotency of the function is that it returns the same results no matter how many times it is executed until the underlying data is changed ?

+6
source share
3 answers

By WIKI :

Idempotence (/ ˌaɪdɨmpoʊtəns / eye-dəm-poh-təns) is a property of certain operations in mathematics and computer science that they can be applied several times without changing the result outside the original application

There is a good blog that talks about idempotency of requests:

Idempotent means that executing a request 10 times has the same effect as once. An idempotent query may create something in the database for the first time, but it will not do it again. Or he will simply return a link to him next time. As a friend told me:

In the perspective of browsers, there is no difference than if the answer always existed all the time until the first request. For example, you can cache this response without any tangible effect, and bots can request it again and again without damaging anything.

Idempotent is exactly what DecentURL or SnipURL creates, and why GET was allowed to be used. You do this for the first time, and the service creates an entry in the database. But theres no harm in getting it again - the service just grabs the existing database entry.

+2
source

GET is idempotent because it does not (or should not) change the resource. This does not require the resource to be static, and nothing else (such as a message) will ever change it.

+2
source

The idempotent is due to the fact that GET calls do not change the called resource.

Other methods are another matter.

+2
source

Source: https://habr.com/ru/post/927056/


All Articles