0
0
Expressframework~8 mins

Why REST principles matter in Express - Performance Evidence

Choose your learning style9 modes available
Performance: Why REST principles matter
MEDIUM IMPACT
This affects how quickly and efficiently a web API responds to requests, impacting server response time and client rendering speed.
Designing an API endpoint for fetching user data
Express
app.get('/users/1', (req, res) => {
  // returns only necessary user info following REST resource URL
  res.json({ id: 1, name: 'Alice' });
});
Uses clear resource URL and returns minimal necessary data, reducing payload and speeding response.
📈 Performance GainReduces payload size by 30-50%, improves response time and client rendering speed.
Designing an API endpoint for fetching user data
Express
app.get('/getUserData', (req, res) => {
  // returns all user data including unnecessary nested info
  res.json({ user: { id: 1, name: 'Alice', password: 'secret', settings: { theme: 'dark', notifications: true } } });
});
Returns excessive data and uses non-resource-oriented URL, causing larger payloads and slower client rendering.
📉 Performance CostIncreases payload size by 30-50%, slows response time, and delays client rendering.
Performance Comparison
PatternPayload SizeServer ProcessingCachingVerdict
Non-RESTful API (large payload, unclear URLs)HighHighNo[X] Bad
RESTful API (minimal payload, clear URLs)LowLowYes[OK] Good
Rendering Pipeline
REST principles influence how quickly the server can process requests and send responses, which affects the browser's ability to start rendering content.
Network Request
Server Processing
Response Parsing
Rendering
⚠️ BottleneckServer Processing and Network Request due to inefficient API design
Core Web Vital Affected
INP
This affects how quickly and efficiently a web API responds to requests, impacting server response time and client rendering speed.
Optimization Tips
1Use clear, resource-oriented URLs to improve caching and routing.
2Return only necessary data to reduce payload size and speed up responses.
3Use correct HTTP methods to enable browser caching and efficient server processing.
Performance Quiz - 3 Questions
Test your performance knowledge
Which REST principle helps reduce server processing time and speeds up client rendering?
AUsing clear resource URLs and minimal payloads
BUsing POST for all requests regardless of action
CReturning all user data including sensitive info
DIgnoring HTTP status codes
DevTools: Network
How to check: Open DevTools, go to Network tab, reload the API request, and inspect the request URL, method, and response size.
What to look for: Look for clear resource URLs, correct HTTP methods (GET, PUT, POST, DELETE), and small response payload sizes for better performance.