REST and GraphQL are the two most common ways to design a web API. REST exposes resources at many URLs and uses HTTP methods and status codes for meaning. GraphQL exposes one endpoint and lets clients ask for exactly the data they need using a typed query language. Neither is better in general; they make different trade-offs. This guide compares them on the points that matter in practice.
To show a user's profile with their three latest posts, a REST client might make two requests:
textGET /users/42 GET /users/42/posts?limit=3
A GraphQL client sends one:
graphqlquery { user(id: "42") { name avatarUrl posts(last: 3) { title publishedAt } } }
| REST | GraphQL | |
|---|---|---|
| Endpoints | Many, one per resource | Usually one (/graphql) |
| Response shape | Decided by the server | Decided by the client's query |
| Over-fetching | Common (full resources) | Avoided (only requested fields) |
| Under-fetching | Common (several round trips) | Avoided (nested fields in one query) |
| Contract | OpenAPI (optional) | Schema (built in, typed) |
| HTTP caching | Excellent (GET + URLs + CDNs) | Harder (usually POST to one URL) |
| Error signaling | HTTP status codes | errors array, usually with HTTP 200 |
| File uploads | Native multipart | Needs extensions or a separate endpoint |
| Real-time | Webhooks, SSE, WebSockets | Subscriptions (often over WebSocket) |
| Tooling to start | Any HTTP client, curl | GraphQL client and schema tooling |
curl.404, 429 and 503 out of the box.errors array; see Introduction to GraphQL queries.Many teams use REST for public, cacheable and file-heavy endpoints, and GraphQL for their own apps' data needs. Some put a GraphQL layer in front of existing REST services. Both return JSON, so the same habits apply: consistent naming, clear error shapes and validated responses.
Explore a GraphQL API with the GraphQL Client, which loads the schema so you can browse types while you write queries. For REST, curl plus the JSON Formatter for reading responses goes a long way; see Best practices for testing REST APIs.