Skip to content
Devgo

REST vs GraphQL

REST uses HTTP verbs on resources; GraphQL uses a query language to fetch exactly what you need. REST is simpler and cacheable; GraphQL is flexible and avoids over-fetching. Choose REST for simple CRUD, GraphQL for complex data requirements.

When to use
  • REST: simple CRUD, public APIs, when caching matters.
  • GraphQL: complex frontends, mobile (bandwidth-sensitive), when clients need flexible data.
When not to
  • REST: complex data requirements (GraphQL better).
  • GraphQL: simple CRUD (REST simpler).

Definition

: endpoints per resource (/users/1), verbs, fixed responses. : single endpoint, query language describes exactly what data you want, typed schema, resolvers fetch fields. GraphQL avoids over/under-fetching but adds complexity.

Why it exists

is simple but inflexible (fixed response shapes). was created to let clients specify exactly what data they need — solving over-fetching (too much data) and under-fetching (multiple round trips).

How it works

: GET /users/1 returns a fixed shape. : query { user(id: 1) { name, posts { title } } } returns exactly what you asked. Schema defines types and fields. Resolvers fetch data. Single endpoint (POST /graphql).

Scaling limits

: over/under-fetching, versioning. : complexity, caching is harder, N+1 queries, DoS surface (arbitrary queries).

Cost shape

Both free. needs a server library (Apollo, Yoga). needs nothing extra.

Alternatives

  • REST — Simpler, standard, less flexible.
  • gRPC — Internal APIs, typed, efficient, not for browsers.
  • tRPC — -only, no schema needed, internal APIs.

Failure modes

  • : over-fetching.
  • : complexity, caching, DoS.
  • Both: N+1 queries.

, , ,