The shapes
- REST exposes many endpoints, one per resource, and the server decides the response shape.
- GraphQL exposes one endpoint with a typed schema, and the client asks for exactly the fields it needs in a single query.
Why GraphQL appeals
- No over fetching: a mobile screen requests only the fields it shows instead of a fat resource.
- No under fetching: a screen that would need three REST calls can fetch a nested graph in one round trip.
- Strong typing: the schema is a contract that powers tooling and validation.
What GraphQL costs
- Caching is harder: REST leans on HTTP caching by URL, while GraphQL posts queries that vary, so caching moves into the client or a persisted query layer.
- Server complexity: resolvers can trigger many backend calls, and a careless query causes the N plus one problem.
- Query cost control: clients can ask for deep expensive graphs, so you add depth limits and cost analysis.
When to pick which
- REST fits simple public APIs with strong HTTP caching.
- GraphQL fits rich clients that aggregate many sources and value flexibility.
Key idea
GraphQL trades easy HTTP caching and simple servers for client driven field selection, so the right choice depends on whether flexible fetching or cache friendliness matters more.