Choosing an API style is mainly about how client and server exchange data and what the interface is meant for. The five common approaches differ in data format, flexibility, and communication pattern.
| Paradigm | Format / Transport | Communication | Typical use |
|---|---|---|---|
| REST | JSON over HTTP | Request/response, well cacheable | Broad, public web APIs |
| GraphQL | JSON, a flexible query over HTTP | Request/response, exactly the fields | Flexible, nested data for frontends |
| gRPC | Protocol Buffers (binary), HTTP/2 | RPC, fast and strongly typed | Internal microservices in the backend |
| SOAP | XML with fixed contracts | Request/response, strictly standardized | Formal enterprise integrations |
| WebSockets | Arbitrary, persistent connection | Bidirectional, real-time (push) | Chats, live updates, dashboards |
More depth per style: REST, GraphQL, gRPC and Real-Time & Events.
In practice these styles aren't mutually exclusive: REST and GraphQL can share the same data store, gRPC dominates internally between services, and WebSockets add a real-time channel on top of request-response APIs.
GraphQL request: exactly the desired fields
{
user(id: "42") {
name
email
posts(last: 2) { title }
}
}GraphQL: a single request returns exactly the requested fields, here name, email, and a user's last two posts.
Sources
- Learn GraphQL GraphQL.org
- Introduction to gRPC gRPC.io
- The WebSocket API (WebSockets) MDN Web Docs
- What is the Difference Between GraphQL and REST? Amazon Web Services (AWS)