Search code examples
restapi-design

REST API Design What method should I use for endpoint which calls third party API?


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


Solution

  • 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.