202 Accepted
Success - Request accepted, processing pending
HTTP 202 Accepted
What It Means
The HTTP 202 Accepted status code indicates that the request has been accepted for processing, but the processing has not been completed. The request might or might not eventually be acted upon, as it might be disallowed when processing actually takes place.
When to Use 202
- Background jobs: Video encoding, report generation, data exports
- Email sending: Queued for delivery but not yet sent
- Batch operations: Processing large datasets asynchronously
- Webhooks: Acknowledging receipt before processing
Example Response
HTTP/1.1 202 Accepted
Content-Type: application/json
Location: /jobs/abc123
{
"job_id": "abc123",
"status": "pending",
"status_url": "/jobs/abc123",
"estimated_completion": "2025-01-15T10:30:00Z"
}
Best Practices
- Include a
Locationheader pointing to a status endpoint - Return a job ID the client can use to check status
- Provide an estimated completion time if possible
- Consider webhooks for notifying when processing completes
Polling Pattern
# 1. Client submits job
POST /exports HTTP/1.1
→ 202 Accepted { "job_id": "abc123" }
# 2. Client polls for status
GET /jobs/abc123 HTTP/1.1
→ 200 OK { "status": "processing", "progress": 45 }
# 3. Eventually...
GET /jobs/abc123 HTTP/1.1
→ 200 OK { "status": "complete", "result_url": "/exports/abc123.csv" }
202 vs 200 vs 201
| Code | Use When |
|---|---|
| 200 | Request complete, returning result now |
| 201 | Resource created immediately |
| 202 | Request accepted, will process later |