API styles compared: REST, GraphQL, gRPC, SOAP and JSON-RPC
In short: There are several ways to build interfaces: REST is universal, GraphQL flexible for clients, gRPC fast between services, SOAP formal and JSON-RPC lean.
In more detail: An API (interface) defines how programs talk to each other. The choice of style influences performance, effort and tools. There is no “best”, only a suitable approach.
In Depth
REST
Resources with URLs (/users/42), standard HTTP methods (GET, POST, PUT, DELETE), mostly JSON. Strengths: simple, supported everywhere, well cacheable, easy to test (curl, browser). Weaknesses: over-/under-fetching (too much or too little data per request), several requests for nested data, versioning needed. Described with OpenAPI.
GraphQL
One endpoint; the client describes which fields it wants:
{ user(id: 42) { name orders { total } } }Strengths: exactly the data needed, one request for nested data, strong schema/types, good for frontends and mobile apps. Weaknesses: caching more complicated, defend against complexity attacks (too deep queries), N+1 problems in the server, learning effort.
gRPC
From Google, uses Protocol Buffers (compact binary formats) over HTTP/2 with streaming in both directions and code generation for many languages. Strengths: very fast, clear contracts (.proto), ideal for microservices among themselves. Weaknesses: in the browser only via detours (gRPC-Web), binary format harder to debug.
SOAP and JSON-RPC
- SOAP: XML-based, formal WSDL schema, standards for security and transactions (WS-*). Common in enterprises/authorities/banks (legacy systems); cumbersome.
- JSON-RPC / XML-RPC: function calls over HTTP (
{"method": "add", "params": [1,2]}), very lean; used in blockchain nodes (Ethereum), editors (LSP Language Server Protocol). - Plus WebSockets/SSE for real time, webhooks for events, tRPC (TypeScript end-to-end types).
Choosing
- Public API for many strangers: REST (+ OpenAPI).
- Complex frontends with changing data needs: GraphQL.
- Internal service-to-service communication with performance needs: gRPC.
- Connecting to legacy systems: SOAP.
- Small, simple calls: JSON-RPC. Always mind authentication, rate limiting, versioning, error formats and documentation.
See also: REST API design, GraphQL and gRPC, OpenAPI and Swagger, WebSockets