The HTTP 202 status code stands for "Accepted". It is a successful response indicating that the request has been received but has not yet been processed.
When is HTTP 202 Used?
- Used for asynchronous processing, where the request is accepted but will be completed later.
- Common in background tasks, such as batch processing, long-running API requests, or delayed execution.
- The server does not guarantee that the request will be completed successfully, only that it has been accepted for processing.
Example Scenarios
- Asynchronous API Calls – A request is accepted, but processing happens in the background.
- File Processing – A file is uploaded, but processing (e.g., virus scanning) will happen later.
- Job Queues – A request to create a report is accepted, but it will be generated later.
Example
Client Request (Submitting a Long-Running Task)
POST /generate-report HTTP/1.1
Host: example.com
Content-Type: application/json
{ "report_type": "monthly_summary" }
Server Response (Task Accepted for Processing)
HTTP/1.1 202 Accepted
Content-Type: application/json
{ "status": "accepted", "task_id": "abc123" }
Summary
HTTP 202 indicates that the request has been accepted but not yet processed. It is useful for asynchronous operations, where the client may need to check back later for the final result.