0
0
GraphQLquery~10 mins

GraphQL vs REST comparison - Visual Side-by-Side Comparison

Choose your learning style9 modes available
Concept Flow - GraphQL vs REST comparison
Client sends request
REST: Fixed endpoints
Server returns fixed data
Client may need multiple requests
Client sends request
GraphQL: Single endpoint
Client specifies data shape
Server returns exactly requested data
Shows how REST uses fixed endpoints returning fixed data, often requiring multiple requests, while GraphQL uses a single endpoint where client specifies exactly what data it wants.
Execution Sample
GraphQL
query {
  user(id: "1") {
    name
    posts {
      title
    }
  }
}
GraphQL query requesting a user's name and their posts' titles in one request.
Execution Table
StepRequest TypeEndpointData RequestedServer ResponseNotes
1REST/users/1User data{"id": "1", "name": "Alice", "email": "alice@example.com"}Fixed data, includes email not needed
2REST/users/1/postsUser's posts[{"id": "101", "title": "Hello World"}, {"id": "102", "title": "GraphQL Intro"}]Separate request for posts
3GraphQL/graphql{ user(id: "1") { name posts { title } } }{"data": {"user": {"name": "Alice", "posts": [{"title": "Hello World"}, {"title": "GraphQL Intro"}]}}}Single request, exact data
4GraphQL/graphql{ user(id: "1") { name } }{"data": {"user": {"name": "Alice"}}}Single request, less data
5REST/users/1User data{"id": "1", "name": "Alice", "email": "alice@example.com"}No way to limit fields in REST
6REST/users/1/postsUser's posts[{"id": "101", "title": "Hello World"}, {"id": "102", "title": "GraphQL Intro"}]Multiple requests needed
7End---Requests complete
💡 All needed data retrieved; REST requires multiple requests, GraphQL uses one with precise data.
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4Final
REST_UserDatanull{"id": "1", "name": "Alice", "email": "alice@example.com"}{"id": "1", "name": "Alice", "email": "alice@example.com"}{"id": "1", "name": "Alice", "email": "alice@example.com"}{"id": "1", "name": "Alice", "email": "alice@example.com"}{"id": "1", "name": "Alice", "email": "alice@example.com"}
REST_UserPostsnullnull[{"id": "101", "title": "Hello World"}, {"id": "102", "title": "GraphQL Intro"}][{"id": "101", "title": "Hello World"}, {"id": "102", "title": "GraphQL Intro"}][{"id": "101", "title": "Hello World"}, {"id": "102", "title": "GraphQL Intro"}][{"id": "101", "title": "Hello World"}, {"id": "102", "title": "GraphQL Intro"}]
GraphQL_Responsenullnullnull{"data": {"user": {"name": "Alice", "posts": [{"title": "Hello World"}, {"title": "GraphQL Intro"}]}}}{"data": {"user": {"name": "Alice"}}}{"data": {"user": {"name": "Alice", "posts": [{"title": "Hello World"}, {"title": "GraphQL Intro"}]}}}
Key Moments - 3 Insights
Why does REST require multiple requests to get user and posts data?
REST endpoints return fixed data per URL. To get user info and posts, separate URLs must be called (see execution_table rows 1 and 2).
How does GraphQL return exactly the data requested?
GraphQL queries specify fields needed. Server returns only those fields in one response (see execution_table row 3).
Can REST limit fields returned in a response like GraphQL?
No, REST endpoints usually return fixed fields. To limit fields, APIs must support query parameters, which is not standard (see execution_table rows 1 and 5).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, at which step does GraphQL return both user name and posts in one response?
AStep 2
BStep 3
CStep 4
DStep 1
💡 Hint
Check the 'Server Response' column for GraphQL requests in execution_table rows.
According to variable_tracker, what is the value of REST_UserPosts after Step 2?
A[{"id": "101", "title": "Hello World"}, {"id": "102", "title": "GraphQL Intro"}]
Bnull
CUser data JSON
DEmpty array
💡 Hint
Look at REST_UserPosts row and After Step 2 column in variable_tracker.
If the GraphQL query in Step 4 requested posts titles only, what would the server response include?
AUser name and posts titles
BUser name only
CPosts titles only
DUser email and posts titles
💡 Hint
GraphQL returns exactly requested fields as shown in execution_table rows 3 and 4.
Concept Snapshot
GraphQL vs REST:
- REST uses multiple fixed endpoints.
- REST returns fixed data per endpoint.
- GraphQL uses single endpoint.
- Client specifies exact data shape in GraphQL.
- GraphQL reduces multiple requests to one.
- REST may over-fetch or under-fetch data.
Full Transcript
This visual compares GraphQL and REST by showing how each handles data requests. REST uses fixed URLs returning fixed data, often requiring multiple requests to get related data like user info and posts. GraphQL uses a single endpoint where the client specifies exactly what data it wants, returning only that data in one response. The execution table traces requests and responses step-by-step, showing REST needing two requests for user and posts, while GraphQL gets both in one. The variable tracker shows how data variables change after each step. Key moments clarify why REST requires multiple calls and how GraphQL returns precise data. The quiz tests understanding of these differences by referencing the tables. The snapshot summarizes the main points for quick recall.