HTTP Methods Overview
HTTP Methods: GET, POST, PUT, PATCH, DELETE
The HTTP protocol defines a set of request methods to indicate the desired action to be performed on a given resource. Designing professional REST APIs requires strict adherence to method semantics, idempotency, and safety.
1. HTTP Methods Comparison Matrix
| Method | CRUD Action | Safe? | Idempotent? | Request Body Allowed? | Standard Success Status |
|---|---|---|---|---|---|
GET | Read / Retrieve | Yes | Yes | No | 200 OK |
POST | Create / Action | No | No | Yes | 201 Created |
PUT | Replace / Overwrite | No | Yes | Yes | 200 OK or 204 No Content |
PATCH | Partial Update | No | No (Technically) | Yes | 200 OK |
DELETE | Destroy / Remove | No | Yes | Optional (Rare) | 204 No Content |
2. Safe vs Idempotent Methods
- Safe Methods: Calling the method never modifies server-side resource state.
GET,HEAD, andOPTIONSare safe (read-only). - Idempotent Methods: Making the exact same request once produces the exact same server-side outcome as making it 100 times.
GET,PUT,DELETE,HEAD, andOPTIONSare idempotent.
3. The PUT vs PATCH Distinction
A frequent source of API design errors is confusing PUT and PATCH:
PUT (Full Resource Replacement):
PUT replaces the entire target resource representation. Any existing fields omitted from the payload are reset to default values or set to null!
PATCH (Partial Modification):
PATCH applies partial delta updates. Only the provided keys are mutated; unmentioned fields remain unchanged:
4. Method Handling in Django REST Framework
DRF simplifies method routing in APIViews:
Practice Quiz
Status Codes
Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
Related Lessons
| Previous Lesson | Next Lesson |
|---|---|
| REST Principles | Status Codes |
Practice Quiz
Test your understanding of this lesson with 5 questions. Each question has one correct answer.