这是三种不同的 API 范式,每一种都为不同的约束而优化。没有普适的赢家——正确的选择取决于使用者、数据形状和网络。
三者速览
REST GraphQL gRPC
Style resources + HTTP single query graph RPC (call methods)
Transport HTTP/1.1, JSON HTTP, JSON HTTP/2, Protobuf (binary)
Fetching fixed endpoints client picks fields fixed methods
Schema optional (OpenAPI) strong, typed strong, .proto
Browser native, cacheable needs client lib limited (needs proxy)
REST
在纯 HTTP 之上面向资源。为公共 API、CRUD service、以及任何受益于 HTTP 缓存、无处不在和简单性的东西。它的弱点是(即使你只需要一个字段,也会拿到整个 )和( 问题:取一个 user,然后循环去取每个 order)。
