APIs
REST vs GraphQL
REST and GraphQL are two approaches to building web APIs. REST exposes many endpoints that each return fixed data shapes; GraphQL exposes a single endpoint where the client asks for exactly the fields it needs.
Side-by-side comparison
| REST | GraphQL | |
|---|---|---|
| Endpoints | Many, one per resource | Usually one |
| Data fetching | Fixed response shape | Client specifies fields |
| Over/under-fetching | Common | Avoided by design |
| Caching | Simple (HTTP caching) | Harder (needs tooling) |
| Learning curve | Low | Higher |
| Versioning | Often via /v1, /v2 | Evolve schema, deprecate fields |
When to use REST
- Simple, resource-oriented APIs
- You want easy HTTP caching and CDN support
- Public APIs where simplicity matters
When to use GraphQL
- Clients need flexible, precise data
- Many clients with different data needs
- You want a strongly-typed schema and tooling
Bottom line
Use REST for simple, cacheable, resource-based APIs. Reach for GraphQL when clients need flexible queries and you want to eliminate over-fetching — at the cost of more setup and caching complexity.