HTTP Status 202 - Accepted

Der HTTP-Status-Code 202 Accepted signalisiert, dass der Request akzeptiert wurde, aber die Verarbeitung noch nicht abgeschlossen ist. Die Aktion wird asynchron durchgeführt. Client erhält typischerweise eine Job-ID oder Status-URL für Polling oder Webhook-Notification.

Typ

Response-Status-Code

Syntax

Der Status Code wird zurückgegeben, wenn Request zur asynchronen Verarbeitung akzeptiert wurde.

http
HTTP/1.1 202 Accepted
Location: /api/jobs/abc-123

Direktiven

Der 202 Accepted Status Code wird für asynchrone Request-Verarbeitung verwendet.

Async Processing
Server akzeptiert Request, führt Processing aber asynchron aus. Response wird sofort zurückgegeben, bevor eigentliche Verarbeitung abgeschlossen ist. Ideal für Long-Running Operations (Video-Encoding, Report-Generierung, Batch-Jobs).
Status Tracking
Response sollte Location Header oder Body mit Status-URL enthalten. Client kann Status periodisch pollen oder Webhook für Completion-Notification registrieren.
No Guarantee
202 garantiert nicht, dass Request erfolgreich verarbeitet wird. Client muss Status-URL prüfen, um finales Ergebnis zu erfahren (Success oder Failure).

Beispiele

Nachfolgend finden Sie praktische Anwendungsbeispiele für Status 202.

Beispiel 1 Video Encoding Job

http
POST /api/videos HTTP/1.1
Host: media.example.com
Content-Type: multipart/form-data

[video file upload]

HTTP/1.1 202 Accepted
Location: /api/jobs/video-enc-789
Content-Type: application/json

{"job_id": "video-enc-789", "status": "queued", "status_url": "/api/jobs/video-enc-789"}

Beispiel 2 Bulk Data Export

http
POST /api/reports/export HTTP/1.1
Host: api.example.com
Content-Type: application/json

{"format": "csv", "date_range": "2025-01-01/2025-09-30"}

HTTP/1.1 202 Accepted
Content-Type: application/json
Retry-After: 60

{"export_id": "exp-42", "status": "processing", "estimated_completion": "2025-10-01T15:00:00Z"}

Beispiel 3 Async Payment Processing

http
POST /api/payments HTTP/1.1
Host: payment.example.com
Content-Type: application/json

{"amount": 99.99, "currency": "EUR", "payment_method": "sepa"}

HTTP/1.1 202 Accepted
Location: /api/payments/pmt-xyz
Content-Type: application/json

{"payment_id": "pmt-xyz", "status": "pending", "webhook_url": "https://merchant.com/webhooks/payment"}

Async Job Processing Flow

Asynchrone Request-Verarbeitung mit 202 Accepted und Status Polling

Vorteile für die Systemarchitektur

  • Non-Blocking API: Server muss nicht auf Long-Running Operations warten, kann sofort antworten. Verhindert Connection Timeouts und ermöglicht horizontales Skalieren von Processing Workers.
  • Decoupled Processing: Request-Handling und Job-Execution sind getrennt. Message Queue oder Job Scheduler verarbeitet Tasks asynchron, ermöglicht Retry-Logic und Load Balancing.
  • Better User Experience: Client erhält sofortige Response statt Timeout bei langläufigen Operations. Status-Polling oder Webhooks informieren über Completion, ermöglicht Progress Bars.

Spezifikation

RFC 9110, Section 15.3.3 – HTTP Semantics https://www.rfc-editor.org/rfc/rfc9110.html#name-202-accepted

Weitere Spezifikationen

POST Method, HTTP Status 200 - OK