Skip to content

TypeScript

REST vs GraphQL

I've built APIs with both REST and GraphQL in production. Neither is universally better. Here's what actually differs.

14 Oct 2023 · 2 min read

REST vs GraphQL

I've built APIs with both REST and GraphQL in production. Neither is universally better. Here's what actually differs.

What is GraphQL?

A query language for APIs. Facebook created it in 2012, open-sourced it in 2015. Instead of multiple endpoints, you have one endpoint and the client describes exactly what data it wants.

Where GraphQL wins

Data fetching. REST often requires multiple round trips. Get the user from /users/1, then their posts from /users/1/posts, then comments from /posts/5/comments. GraphQL fetches all of that in a single request.

No over-fetching or under-fetching. With REST, endpoints return fixed shapes. You get fields you don't need, or you don't get fields you do. GraphQL lets the client specify exactly which fields it wants.

No versioning. Add new fields without breaking existing clients. Old queries keep working. REST usually needs /v1/, /v2/ when the shape changes.

Where REST wins

Caching. REST works naturally with HTTP caching — CDNs, browser caches, ETags. GraphQL sends POST requests to a single endpoint, which makes HTTP-level caching much harder. You need a separate caching layer (Apollo Cache, for example).

Error handling. REST uses HTTP status codes. A 404 means "not found." A 500 means "server error." GraphQL always returns 200 OK, even when things go wrong. Errors are buried in the response body. This makes monitoring and alerting more complex.

Simplicity. REST is easier to understand, easier to debug with curl, and most teams already know it. GraphQL has a steeper learning curve and requires more tooling.

The trade-off

GraphQL is powerful for complex, data-rich frontends with many different views — dashboards, mobile apps, SPAs. REST is simpler and better for straightforward CRUD APIs, public APIs, and teams that don't want to maintain a schema.

Pick based on your problem, not the hype.

Ehsan Gazar helps software engineers take LLM and agent systems from demo to production. He writes about building LLM systems that hold up in production: evals, tracing, RAG, agent architecture and cost control. He teaches the Senior to Staff AI Engineer cohort on Maven, where engineers learn to design and defend these systems.

Go further
Live cohort on Maven

Forward Deployed AI Engineering: From Customer Problem to Production Value

A live Maven cohort for engineers: 10 live 90-minute sessions taking one AI engagement from customer problem to production, ending with eight artefacts and a working slice in your own repo.

January cohort starts Tue 12 Jan 2027, Tue & Thu 6:30pm London. Enrolling now, 20 seats, $1,800.

View the live cohort

Keep reading