A question on idempotence

Not applicable

Hi All,

I have a question on idempotence and general API understanding.

A GET method is considered idempotent

GET /users/12345 = David

GET /users/54321 = Dino

for example

But what if my API is for say a currency pair, and the rate changes every second?

GET /currencies/audusd = $0.70857

and then 1 second later

GET /currencies/audusd = $0.70859 (changed by 2 pips from "7" to "9")

My understanding of the only way to make this GET idempotent is to specify a timestamp for something like

GET /currencies/audusd?time=1538627424 = $0.70860

So what do we call a GET method that returns the most current value of something that is dynamic?

I'd appreciate any feedback or insight.

Cheers

David

1 1 368
1 REPLY 1

Idempotence doesn't imply "same data in every response".

It means "the side effects of multiple requests in series, are the same as the side effects of a single request."

H/T stackexchange.

So in your example,

GET /currencies/audusd

is idempotent, in that it has ZERO side effects (I guess), even if it returns an ever-changing stream of values.

If I were designing it, though, I might try something like

GET /currencyrates/aud/for/usd

or

GET /currencyrates/aud?for=usd