HTTP Methods
Learn how GET, POST, PUT, PATCH, and DELETE map to CRUD operations on your API resources.
HTTP methods tell the server what you want to DO with a resource. They map directly to CRUD operations:
| Method | CRUD | Example |
|--------|------|-------|
| GET | Read | Get user #42 |
| POST | Create | Create a new user |
| PUT | Replace | Replace user #42 entirely |
| PATCH | Update | Update only the user's email |
| DELETE | Delete | Delete user #42 |
This mapping is the core of REST — Representational State Transfer.
Which HTTP method should you use to update only the email field of an existing user?
- APATCH
- BPUT
- CPOST
- DGET
GET /users/42 → always returns same result (idempotent)
PUT /users/42 → replaces with same data (idempotent)
DELETE /users/42 → deleting twice leaves it deleted (idempotent)
POST /users → creates a new user EACH time (NOT idempotent)Idempotent operations are safe to retry on network failure. POST is not — retrying could create duplicates.
A network error occurs during a payment POST. Why is retrying risky?
- APOST is not idempotent — retrying could create a duplicate payment
- BPOST always fails on retry
- CPOST requests cannot be retried
- DThe server discards duplicate POST requests automatically
REST APIs design URLs around resources (nouns), not actions (verbs):
# WRONG — actions in URLs
GET /getUser?id=42
POST /createUser
DELETE /deleteUser?id=42
# RIGHT — resources + HTTP methods
GET /users/42 # get user 42
POST /users # create a user
DELETE /users/42 # delete user 42
GET /users/42/posts # posts by user 42 (nested)Which URL design follows REST best practices for retrieving all orders for user 42?
- AGET /users/42/orders
- BGET /getOrdersByUser?id=42
- CPOST /fetchOrders
- DGET /orders/user/42/all
Complete the HTTP method for replacing an entire user record:___ /users/42
You call DELETE /users/42 successfully. Then you call DELETE /users/42 again. What happens?
- A404 Not Found — the user no longer exists
- B200 OK — DELETE is idempotent
- C409 Conflict — already deleted
- D204 No Content — same as first call