<img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=1063935717132479&amp;ev=PageView&amp;noscript=1 https://www.facebook.com/tr?id=1063935717132479&amp;ev=PageView&amp;noscript=1 "> REST vs. GraphQL

REST vs. GraphQL

As apps grow, especially when multiple clients (web, mobile, third-party) hit the same API, two friction points emerge with plain REST: over-fetching (getting more fields than you need) and under-fetching (needing multiple round trips to assemble a view). GraphQL was designed specifically to fix both: a single endpoint where the client describes exactly the data it wants, and the response mirrors the shape of the query.

query {
  books {
    title          # only this
    author {
      name         # and this
    }
  }
}

Notice what you just read in the previous lessons, though: JSON:API gives REST the same two powers. Sparse fieldsets are field selection; include is nested fetching. The real differences lie elsewhere:

REST + JSON:API Client GET /books GET /authors GET /reviews many URLs · one per resource GraphQL Client POST /graphql one endpoint one query · exact shape
REST spreads a view across several resource URLs; GraphQL exposes one endpoint where the query body decides exactly which records and fields come back.
REST + JSON:API GraphQL
EndpointsMany URLs, one per resourceOne URL; the query body decides
Field selectionfields[type]=...Part of every query
Related datainclude=authorNested in the query
HTTP cachingGET URLs cache in browsers and CDNs for freeAll POSTs to one endpoint — needs persisted queries to cache
ContractConventions in docsTyped, introspectable schema with autocomplete tooling
Server costPredictable queriesArbitrary queries; resolvers can hide a database N+1 (use DataLoader)

The schema is also an access-control boundary: if a field isn't in the GraphQL schema, no client can ever request it. With REST, omitting a field is a per-endpoint decision.

Rule of thumb: REST with JSON:API conventions is hard to beat for public, cacheable, CRUD-shaped APIs. GraphQL earns its complexity when many differently-shaped clients consume the same rich data graph and you want one flexible contract instead of an endpoint per view.

Check your understanding

Check your understanding

Your GraphQL API answers one HTTP request per view, but the database logs show one query per book's author. What's happening?

Check your understanding

Why do REST APIs get CDN caching 'for free' while GraphQL APIs don't?