Performance: Why REST design principles matter
This affects how quickly and efficiently a web API responds and scales under load, impacting server response time and client rendering speed.
app.get('/users/:id', (req, res) => { /* fetch user data by id */ });
app.post('/getUserData', (req, res) => { /* fetch user data */ });
| Pattern | Server Processing | Caching | Network Overhead | Verdict |
|---|---|---|---|---|
| Using POST for data retrieval | High CPU usage | No caching | High | [X] Bad |
| Using GET with resource paths | Low CPU usage | Cacheable | Low | [OK] Good |
| Stateful session management | High memory use | No caching | High | [X] Bad |
| Stateless API requests | Low memory use | Cacheable | Low | [OK] Good |
PUT to update an existing resource correctly pairs PUT with updating a resource. Other options mismatch methods and actions.app.delete('/users/:id', (req, res) => {
// delete user logic
res.send('User deleted');
});/users/123?app.post('/items/:id', (req, res) => {
// update item logic
res.send('Item updated');
});Pass the test and this pattern moves unknown