On the idempotence of GET
Asked Answered
C

2

8

I have been doing some reading on the GET HTTP method and in particular on its idempotent quality.

This is my understanding: if I call a 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 database of films and I perform a GET operation in which I return all the James Bond films in the database.
Imagine I run this query a million times and after the 500,000th time someone else runs a POST query on the database adding a new Bond film.
Well, now half the GET operations return N results and the other half return N+1 results.

Does this not then break idempotence as it is usually described?
Would not a better definition be that the idempotence of a function is that it returns the same results no matter how many times it is executed as long as the underlying data does not change?

Carltoncarly answered 5/10, 2012 at 19:2 Comment(0)
S
2

GET idempotent because it does not (or should not) change the resource. This does not require that the resource is static and nothing else (like a post) never changes it.

Same answered 5/10, 2012 at 19:5 Comment(0)
R
2

The idempotence is about the fact that the GET calls do not change the resource being called.

What other methods do is a different matter.

Redivivus answered 5/10, 2012 at 19:5 Comment(3)
Is it that GET doesn't change the resource being called or that GET returns the same result each time?Carltoncarly
@SachinKainth - Is it that GET doesn't change the resource being called. That's it.Redivivus
Makes sense, however the term “idempotence” is different for GET vs PUT. An idempotent PUT changes the state of a result on initial application. However, GET doesn’t change the state of the resource at all. Or do I miss something? Also when GETting a list from a resource, the list may vary in size (of elements) every time a GET operation is performed.Kaiser

© 2022 - 2024 — McMap. All rights reserved.