GraphQL vs REST Reference Cheat Sheet
A printable reference covering REST resources, GraphQL queries, endpoints, overfetching, underfetching, schemas, resolvers, and HTTP methods for grades 11-12.
Related Labs
GraphQL and REST are two common ways for applications to request data from servers. This cheat sheet helps students compare how each approach organizes requests, responses, endpoints, and data shapes. Understanding the differences is important for building APIs, choosing tools, and debugging client-server communication. It also helps students read modern web application code with more confidence. REST is resource-based, so clients usually request fixed URLs such as /users/42 or /posts using HTTP methods like GET, POST, PUT, PATCH, and DELETE. GraphQL is query-based, so clients send a structured query that asks for exactly the fields they need. REST often uses multiple endpoints, while GraphQL often uses one endpoint with a schema that defines available types and operations. The best choice depends on the project, performance needs, caching strategy, team skills, and how often the data requirements change.
Key Facts
- REST models data as resources, so a URL such as /users/42 represents a specific user resource.
- GraphQL models data as a graph of typed objects, so a query can request related fields such as user { name posts { title } }.
- REST commonly uses HTTP methods with meanings: GET reads data, POST creates data, PUT replaces data, PATCH updates part of data, and DELETE removes data.
- GraphQL commonly sends queries and mutations to one endpoint such as /graphql, where query reads data and mutation changes data.
- Overfetching happens when an API returns more data than the client needs, and GraphQL reduces this by letting the client choose fields.
- Underfetching happens when one request does not return enough data, and GraphQL can reduce this by requesting related data in one query.
- A REST response shape is usually controlled by the server endpoint, while a GraphQL response shape mirrors the client query.
- GraphQL APIs depend on a schema, and a resolver function supplies the data for a field or type.
Vocabulary
- REST
- REST is an API style that organizes data around resources identified by URLs and uses standard HTTP methods.
- GraphQL
- GraphQL is a query language and API runtime that lets clients request specific fields from a typed schema.
- Endpoint
- An endpoint is a URL where a client sends an API request, such as /users or /graphql.
- Schema
- A schema defines the available types, fields, queries, and mutations in a GraphQL API.
- Resolver
- A resolver is a function that returns the data for a specific GraphQL field or operation.
- Overfetching
- Overfetching occurs when an API response includes more data than the client actually needs.
Common Mistakes to Avoid
- Assuming GraphQL is always faster than REST, which is wrong because performance depends on query design, database access, caching, and server implementation.
- Using POST for every REST action, which is wrong because REST relies on HTTP method meaning, such as GET for reading and DELETE for removing resources.
- Ignoring GraphQL query complexity, which is wrong because deeply nested queries can overload a server if limits, pagination, or cost controls are missing.
- Treating REST endpoints as random function names, which is wrong because REST URLs should represent resources such as /orders/15 rather than actions such as /getOrderNow.
- Forgetting that GraphQL still uses HTTP in many systems, which is wrong because GraphQL often travels over HTTP even though its request model differs from REST.
Practice Questions
- 1 A client needs only a user's id and email, but a REST endpoint returns id, email, address, phone, profile photo, and settings. What problem is this, and how could GraphQL reduce it?
- 2 A REST API has /users/8 and /users/8/posts. How many requests are needed to fetch user 8 and that user's posts if each endpoint must be called separately?
- 3 Write a simple GraphQL query that requests a user's name and the titles of that user's posts.
- 4 A team is building a public API with strong HTTP caching needs and stable resource shapes. Should they automatically choose GraphQL over REST? Explain the reasoning.