是否需要 GET 请求 API 因为 POST 在各个方面都更好?

Is there ever a need to have GET request API as POST is better in every way?

所以我们从头开始一个新项目,其中一位开发人员建议为什么要有任何 GET API 请求,因为 POST API 在各个方面都更好。 (至少在使用移动客户端时)

进一步研究发现 POST 可以做 GET 可以做的一切,而且可以做得更好 -

那么,有一个 GET API 的理由吗? (这将仅用于移动客户端,因此浏览器特定缓存不会影响我们)

Is there ever a need to have GET request API as POST is better in every way?

总的来说,是的。在您的具体情况下——也许不会。

GETPOSTmethod tokens

The request method token is the primary source of request semantics

它们是包含在 http 请求中的一种元数据形式,因此通用组件可以了解请求语义并做出建设性贡献。

POST is, in a sense, the wildcard method - it can mean anything。但这样做的后果之一是——因为该方法具有不受约束的语义,通用组件除了传递请求外不能做任何有用的事情。

GET, however, has safe semantics (which includes idempotent 语义)。因为请求是幂等的,通用组件知道它们可以在服务器 returns 没有响应时重新发送 GET 请求(即消息在不可靠的传输中丢失);通用组件可以知道可以预取资源的表示,从而减少感知延迟。

您之前将缓存视为一个问题,但您可能需要重新考虑 - cache constraint 是帮助网络接管世界的重要元素。

将所有内容减少到 POST 将 HTTP 从 application for transferring documents over a network 减少到哑传输。

使用 HTTP 进行传输不一定是错误的:简单对象访问协议 (SOAP) works that way, as does gRPC。您仍然可以获得授权和条件请求;您可能需要自己实现的 HTTP 功能。

此时您没有进行 REST,但没关系;不是每个人都必须这样做。

That doesn’t mean that I think everyone should design their own systems according to the REST architectural style. REST is intended for long-lived network-based applications that span multiple organizations. If you don’t see a need for the constraints, then don’t use them. (Fielding, 2008)