7

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?

rene
  • 41,474
  • 78
  • 114
  • 152
Sachin Kainth
  • 45,256
  • 81
  • 201
  • 304

2 Answers2

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.

Ray
  • 40,256
  • 21
  • 101
  • 138
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.

Oded
  • 489,969
  • 99
  • 883
  • 1,009
  • Is it that GET doesn't change the resource being called or that GET returns the same result each time? – Sachin Kainth Oct 05 '12 at 22:40
  • @SachinKainth - `Is it that GET doesn't change the resource being called`. That's it. – Oded Oct 06 '12 at 06:20
  • 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. – Alex Apr 09 '15 at 06:21