0
0
Expressframework~10 mins

REST vs GraphQL awareness in Express - Visual Side-by-Side Comparison

Choose your learning style9 modes available
Concept Flow - REST vs GraphQL awareness
Client sends request
REST API Endpoint
Server processes
Send fixed data
Client receives
Shows how client requests go to REST or GraphQL endpoints, and how servers respond with fixed or flexible data.
Execution Sample
Express
const express = require('express');
const app = express();

// REST endpoint
app.get('/users', (req, res) => {
  res.json([{ id: 1, name: 'Alice' }]);
});
A simple REST endpoint that returns a fixed list of users.
Execution Table
StepRequest TypeEndpointServer ActionResponse Sent
1GET/usersReturn full user list[{ id: 1, name: 'Alice' }]
2POST/graphqlParse query, resolve fields{ data: { user: { id: 1, name: 'Alice' } } }
3GET/users?id=1Return full user list (no filtering)[{ id: 1, name: 'Alice' }]
4POST/graphqlParse query, resolve only requested fields{ data: { user: { name: 'Alice' } } }
5N/AN/ANo more requestsEnd of trace
💡 No more requests to process, execution ends.
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 4Final
requestTypeN/AGETPOSTPOSTN/A
endpointN/A/users/graphql/graphqlN/A
responseDataN/A[{ id: 1, name: 'Alice' }]{ data: { user: { id: 1, name: 'Alice' } } }{ data: { user: { name: 'Alice' } } }N/A
Key Moments - 2 Insights
Why does the REST endpoint always return the full user data even if I want only the name?
REST endpoints return fixed data shapes defined by the server, so filtering fields requires extra endpoints or query parameters. See execution_table step 1 and 3 where full user data is returned.
How does GraphQL return only the requested fields?
GraphQL parses the query to know exactly which fields the client wants, then resolves and sends only those fields. See execution_table steps 2 and 4 where different fields are returned.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what response does the REST endpoint send at step 3?
A{ data: { user: { name: 'Alice' } } }
B{ data: { user: { id: 1, name: 'Alice' } } }
C[{ id: 1, name: 'Alice' }]
DEmpty response
💡 Hint
Check the 'Response Sent' column for step 3 in the execution_table.
At which step does GraphQL return only the user's name?
AStep 4
BStep 1
CStep 2
DStep 3
💡 Hint
Look at the 'Response Sent' column for GraphQL responses in execution_table steps 2 and 4.
If the client wants only user IDs, how would the REST response change compared to GraphQL?
AREST would send only IDs by default
BREST would still send full user data unless a new endpoint is made
CGraphQL cannot filter fields
DBoth REST and GraphQL send full data always
💡 Hint
Refer to key_moments about REST fixed data shapes and GraphQL flexible queries.
Concept Snapshot
REST vs GraphQL quick view:
- REST: Multiple endpoints, fixed data per endpoint
- GraphQL: Single endpoint, flexible queries
- REST returns full data; GraphQL returns requested fields
- REST needs new endpoints for new data shapes
- GraphQL queries specify exactly what data is needed
Full Transcript
This visual trace compares REST and GraphQL in an Express server. The client sends requests to either REST endpoints or a GraphQL endpoint. REST endpoints return fixed data shapes, so even if the client wants only part of the data, the full data is sent. GraphQL parses the query to return only requested fields, making data transfer efficient. The execution table shows requests and responses step-by-step, highlighting how REST always sends full user data while GraphQL can send partial data. Variable tracking shows request types, endpoints, and response data changing over time. Key moments clarify why REST returns fixed data and how GraphQL filters fields. The quiz tests understanding of these differences using the execution visuals.