Web services using HTTP verbs
Day 128 of 149
👉 Full deep-dive with code examples
The Library Analogy
A library with standard commands:
- GET a book - Receive book
- POST a book - Donate new book
- PUT a book - Replace with updated version
- DELETE a book - Remove from library
REST APIs use the same HTTP verbs to operate on resources.
HTTP Methods = CRUD
| Method | Action | Example |
|---|---|---|
| GET | Read | GET /users |
| POST | Create | POST /users |
| PUT | Update | PUT /users/1 |
| DELETE | Delete | DELETE /users/1 |
Real Example
// Get all users
const users = await fetch("/api/users");
// Create user
await fetch("/api/users", {
method: "POST",
body: JSON.stringify({ name: "Alice" }),
});
Best Practices
- Use nouns, not verbs (
/usersnot/getUsers) - Use plurals (
/productsnot/product) - Return proper status codes (200, 201, 404, etc.)
In One Sentence
REST APIs use standard HTTP methods (GET, POST, PUT, DELETE) to interact with resources identified by URLs.
🔗 Enjoying these? Follow for daily ELI5 explanations!
Making complex tech concepts simple, one day at a time.
Top comments (0)