📌 200 vs 201 vs 202 HTTP Status Codes
These codes are all 2xx Success responses, meaning the request was successful, but their meaning differs.
1️⃣ 200 OK
Definition:
The request was successful, and the response contains the requested data (for GET) or confirms the action (for POST/PUT/DELETE).
Key Points:
- Standard success response.
- Response body usually contains the requested resource.
- No new resource is necessarily created.
Example:
GET /users/1→ 200 OK + user data in response.PUT /users/1→ 200 OK + updated user data.
2️⃣ 201 Created
Definition:
The request was successful, and as a result, a new resource has been created.
Key Points:
- Typically used with POST requests.
- Response often includes
Locationheader pointing to the newly created resource.
Example:
POST /users→ 201 Created + URL of new user inLocationheader.
3️⃣ 202 Accepted
Definition:
The request has been accepted for processing, but the processing is not complete yet.
Key Points:
- Often used for asynchronous operations.
- Response does not guarantee success, only that the request was accepted.
- Client may need to poll or check status later.
Example:
POST /reports→ 202 Accepted + status URL to check report generation.
4️⃣ Comparison Table
| Status Code | Meaning | Typical Use Case | Response Body / Headers |
|---|---|---|---|
| 200 OK | Request successful | GET, PUT, DELETE | Requested data or confirmation |
| 201 Created | Resource successfully created | POST | Location header with URL |
| 202 Accepted | Request accepted, processing pending | Async operations, background jobs | Status URL or info about progress |
5️⃣ Analogy
- 200 OK: Like your order at a cafe is served immediately.
- 201 Created: Like your order was placed and a new table reservation was made for you.
- 202 Accepted: Like your order was received but the chef will start cooking later.
💡 Key takeaway:
- 200 → Done & result ready
- 201 → New resource created
- 202 → Accepted, work in progress