REST vs GraphQL

REST models the world as resources (URLs) and uses HTTP methods to act on them. GraphQL exposes a single endpoint and lets the client request exactly the fields and shape of data it needs in one query.

REST: multiple endpoints, fixed responses

Each resource has its own URL. The server decides the response shape. To get a user and their posts you might call two endpoints (or a custom “compound” endpoint).

flowchart LR subgraph REST A[GET /users/1] --> U[User JSON] B[GET /users/1/posts] --> P[Posts JSON] end

GraphQL: one endpoint, client-defined shape

One POST to /graphql with a query. The client specifies fields (e.g. user + nested posts). Server resolves and returns only what was asked.

flowchart LR subgraph GraphQL Q[POST /graphql\nquery user+posts] --> R[Single response\nuser + posts] end

Comparison

AspectRESTGraphQL
EndpointsMany (per resource)One (or few)
Response shapeServer-definedClient-defined
Over-fetchingPossibleAvoided by design
Under-fetchingMultiple round-trips possibleOne query for related data
CachingHTTP cache (URL = key)More complex (normalized caches)
Learning curveSimplerQuery language + schema

When to use REST: Simple CRUD, strong HTTP caching, broad tooling. When to use GraphQL: Complex UIs needing flexible shapes, many clients with different needs, reducing over/under-fetching.