REST API 设计调用第三方的端点应该使用什么方法API?

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

我已经阅读了 REST API 中的幂等方法和非幂等方法,现在我正在创建一个 REST API,其中有一个调用第三方的端点 API即航班搜索。该端点适合的 HTTP 方法是什么?

GET flights/from=khi&to=dxb&adults=1&date=2020-01-01

如果我使用 GET 方法,那么幂等性如何呢?它表示对端点的每个请求的结果应该相同。在我的例子中,航班搜索 API 可能会 return 改变结果,这些结果最终会在轻微转换后从我的端点 return 编辑。这会影响幂等性还是我应该为此目的使用 POST 方法?

谢谢

就像您直接访问数据库一样,实际的响应代码可能会有所不同。 幂等性是关于您的调用对资源的影响。

你的调用对第三方的影响API总是一样的,不管你调用1次还是100次。资源可能会随着时间的推移而改变,但你永远不会改变资源使用 GET 请求。这就是为什么它是幂等的。

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.

GET 的语义是safe, which is a stronger constraint than idempotent:

safe request methods are idempotent.

GET 的语义是请求 current selected representation for the target resource。 “当前”意味着所选表示可以随时间变化,即使在请求之间也是如此。

您的表示依赖于第三方服务的事实是实现细节,不会改变请求或响应的语义。