GraphQL vs REST

GraphQL directly addresses two common REST pain points: over-fetching (getting more than you need) and under-fetching (needing several requests to assemble one view).

The two problems

  • Over-fetching β€” a REST endpoint returns a fixed, often-large payload even when you need two fields.
  • Under-fetching β€” building one screen needs /user, then /user/1/posts, then /posts/5/comments (the β€œwaterfall”).

GraphQL fixes both: one query fetches exactly the fields you want across related resources.

Side by side

RESTGraphQL
Endpointsmany (one per resource)one
Response shapefixed per endpointclient decides
Multiple resourcesseveral requestsone query
Versioningoften /v1, /v2evolve the schema, deprecate fields
HTTP cachingbuilt-in (GET + URLs)needs extra work

One request vs a waterfall

compare
# REST: 3 round-trips
GET /users/1
GET /users/1/posts
GET /posts/5/comments

# GraphQL: 1 query
query { user(id:1){ name posts{ title comments{ text } } } }

Where REST still wins

  • Simple CRUD APIs β€” REST is less machinery.
  • HTTP caching / CDNs β€” REST GETs cache naturally.
  • File uploads/downloads and standard status codes.
Note: GraphQL isn't universally β€œbetter” β€” it trades REST's simplicity and free HTTP caching for flexibility. Many teams use both: GraphQL for rich client APIs, REST for simple service-to-service endpoints.
Tip: Choose GraphQL when many clients need different, related slices of data (especially mobile). Choose REST when the API is simple, cache-heavy, or you want to lean on HTTP's built-in semantics.
Free preview. Sign in and subscribe to unlock all 809 lessons across 25 courses.
GraphQL vs REST β€” GraphQL | Full Stack Learning Simplified