Skip to main content

REST API vs GraphQL Simulator

Compare REST and GraphQL side-by-side. Understand over-fetching, under-fetching, the N+1 problem, and when to use each approach with interactive scenarios.

Category: API Design

What You Will Learn

  • Compare REST and GraphQL request patterns
  • Understand over-fetching and under-fetching
  • Learn when to choose REST vs GraphQL

Topics covered: api, rest, graphql, educational, interactive, backend

// simulator

REST API vs GraphQL Simulator

Compare REST and GraphQL side-by-side. Understand over-fetching, under-fetching, the N+1 problem, and when to use each approach with interactive scenarios.

Supported byBecome a sponsor
BitriseAtomsizedDigitalOceanDevDojoSMTPfastQuizAPI
0/3

Simple Fetch

Goal: Compare one user profile over REST and GraphQL. Keep Simple Fetch in the menu and press Run comparison.

Simple Fetch ready to run.

Get basic user profile information

Each REST request waits for the preceding resource in this scenario.

1:1 requests

REST total

not run yet

GraphQL total

not run yet

REST API
1 request(s)
GET/api/users/123
GraphQL
1 request
POST/graphql
One request selects only the fields this view needs.

Overview

REST and GraphQL are two ways to design an API, and the difference shows up most clearly when a screen needs data from several places. This simulator runs the same data needs against both styles and shows the requests that travel and the data that comes back. In a simple fetch the two look much alike. With nested data, such as a user and their posts, REST needs a second request. With related data, such as the comments on each post, the number of REST requests grows with every post, the N+1 problem, while one GraphQL query asks for exactly the nested fields. REST also tends to over-fetch, returning whole objects when the screen needs two fields. GraphQL avoids both by letting the client describe the shape of the response. The trade-offs run the other way too: GraphQL moves complexity to the server, makes HTTP caching harder and needs limits on query depth, while REST stays simple to cache and reason about. The goal is to pick the right tool for each API rather than a winner.

Try this

  1. Run "Simple Fetch" in both styles and compare the requests and payloads.
  2. Switch to "Related Data" and count the REST requests, one more for every post, compared with a single GraphQL query.
  3. Use "Multiple Resources" to see over-fetching in REST responses next to the fields GraphQL returns.

Frequently asked questions

What is over-fetching?
Getting more data than the client needs, such as a full user object when the screen only shows a name. It wastes bandwidth and is common with fixed REST endpoints.
Is GraphQL faster than REST?
Not inherently. GraphQL can reduce round trips and payload size, but a complex query can be expensive to resolve on the server, and REST responses are easier to cache over HTTP.
When should I choose REST over GraphQL?
When the API is resource oriented, clients are simple or public, and HTTP caching matters. GraphQL fits best when many clients need different shapes of the same related data.

Try next

Sponsored
Carbon Ads