Reputation: 513
I have read about idempotent methods and non-idempotent methods in REST API and now I am creating a REST API in which there is an endpoint which calls third party API i.e flight search. What could be the suitable HTTP method for that endpoint?
GET flights/from=khi&to=dxb&adults=1&date=2020-01-01
If I use GET method, then what about the idempotency which says that the result should be the same for each request to the endpoint. In my case, the flight search API may return changing results which will eventually be returned from my endpoint after slight transformations. Does that affect the idempotency or should I use POST method for this purpose?
Thanks
Upvotes: 0
Views: 78
Reputation: 57214
If I use GET method, then what about the idempotency which says that the result should be the same for each request to the endpoint. In my case, the flight search API may return changing results which will eventually be returned from my endpoint after slight transformations.
The semantics of GET are safe, which is a stronger constraint than idempotent:
safe request methods are idempotent.
The semantics of GET is that it requests the current selected representation for the target resource. "Current" means that the selected representation can change with time, even between requests.
The fact that your representations depend on a third party service are an implementation detail, and does not change the semantics of the requests or the responses.
Upvotes: 2
Reputation: 1094
Just like if you were going straight to a database, the actual response code can vary. Idempotency is about the effect your call has on the resource.
The effect that your call has on the third party API is always the same, no matter if you make it 1 time or 100. The resource might change over time, but you are never changing the resource with a GET request. That's why it's idempotent.
Upvotes: 3