GraphQL vs REST: What's the Difference?
REST gives you many endpoints that each return a fixed shape; GraphQL gives you one endpoint where the client asks for exactly the fields it wants. How each works, over-fetching and under-fetching, the costs GraphQL adds, and why most small apps should start with REST.
APIs are how your frontend asks your backend for data. (What Is an API?.) Two styles dominate: REST, the long-standing default, and GraphQL, created at Facebook and released in 2015. You'll see both in tutorials and AI-generated code. Here's how they differ.
REST: many endpoints, fixed shapes
A REST API has a URL for each kind of thing, and uses HTTP methods for what you want to do:
GET /api/users/42 → one user
GET /api/users/42/orders → that user's orders
POST /api/orders → create an order
DELETE /api/orders/101 → delete one
Each endpoint returns a shape the server decides:
{
"id": 42,
"name": "Ana",
"email": "[email protected]",
"avatarUrl": "…",
"createdAt": "2026-01-10T09:00:00Z",
"plan": "pro"
}
(What Is CRUD? shows how REST maps to database operations.)
GraphQL: one endpoint, you choose the fields
A GraphQL API usually has a single endpoint — often /graphql — and the client sends a query describing exactly what it wants:
query {
user(id: 42) {
name
orders(last: 3) {
id
total
}
}
}
And gets back exactly that shape:
{
"data": {
"user": {
"name": "Ana",
"orders": [
{ "id": 101, "total": 49.0 },
{ "id": 102, "total": 12.5 }
]
}
}
}
The server publishes a schema — a typed description of everything clients can ask for. Changes are sent as mutations; live updates as subscriptions.
The problems GraphQL solves
Over-fetching. A REST endpoint returns every field, even if the page only needs the name. On a slow mobile connection, that waste adds up.
Under-fetching. A page that needs a user, their orders, and each order's items might need several REST calls, one after another. GraphQL gets it all in one request.
Many different clients. A web app, an iPhone app, and an Android app each need slightly different data. With GraphQL, each asks for what it needs without the backend building custom endpoints for each.
The costs GraphQL adds
- More setup. A schema, resolvers (the functions that fetch each field), and a client library.
- Caching is harder. REST responses cache naturally by URL. GraphQL requests all go to one URL, usually as
POST, so browser and CDN caching don't work out of the box. (What Is Caching?.) - Performance traps. A nested query can trigger a database query per item — the N+1 problem — unless you add batching. (The N+1 Query Problem.)
- Security needs thought. Clients can write expensive queries — deeply nested, or asking for huge lists. You need limits on query depth and cost. And each field needs its own permission checks.
- Errors look different. GraphQL often returns HTTP 200 with an
errorsarray inside, so standard monitoring that watches status codes may miss failures.
Side by side
| REST | GraphQL | |
|---|---|---|
| Endpoints | Many | Usually one |
| Response shape | Decided by server | Decided by client query |
| Over/under-fetching | Common | Avoided |
| HTTP caching | Natural | Needs extra work |
| Learning curve | Low | Moderate |
| Tooling needed | Minimal | Schema, server library, client library |
| Best fit | Most apps, public APIs, simple backends | Many clients with different needs; complex, nested data |
Other options you'll see
- tRPC — for TypeScript apps where the same team writes front end and back end. You call backend functions from the frontend with full type safety, and no API schema to maintain.
- Server actions in Next.js — functions the frontend calls directly. (What Is Next.js?.)
- Supabase and Firebase clients — the front end queries the database through the platform's library.
Which should you use?
For a first app, start with REST — or whatever your framework makes natural. It's simpler to build, debug, cache, and secure, and AI tools produce clean REST APIs reliably. (Designing a REST API That Won't Embarrass You Later.)
Consider GraphQL when you have several client apps with different data needs, deeply connected data, or you're consuming a service that already offers it (GitHub and Shopify, for example, have GraphQL APIs).
You can also mix them: a REST API for most things, GraphQL where it genuinely helps.
EasySpawn runs your backend — REST, GraphQL, or both — as an always-on server alongside a managed database, so Claude Code can test real queries against real data. See how it works or join the waitlist.
Related: What Is an API? · What Is JSON? · API Pagination
Keep reading
What Is an API? Explained Without the Jargon
APIs are how apps talk to each other — how your app takes a payment, sends an email, or asks an AI model a question. What an API actually is, what requests and responses look like, what an API key does, and the few terms you'll keep running into.
What Is a Webhook? Explained for Beginners
A webhook is how another service tells your app that something happened — a payment went through, a form was submitted, a file finished processing. How webhooks differ from normal API calls, what you need to receive one, and the three safety rules every webhook handler must follow.