Intermediate LevelREST APIs & Web Services
How does the Asynchronous Request-Reply Pattern work with HTTP 202 Accepted?
❓ Interview Prompt: Explain Asynchronous Request-Reply Pattern, `202 Accepted` status, `Location` status polling header, background worker queues, and webhook completion.
When an API request initiates a long-running operation (e.g. video encoding, PDF generation taking > 30 seconds), keeping HTTP connections open causes timeouts:
Asynchronous Request-Reply Pattern:
1
Client submits request: 'POST /api/v1/reports'.
2
Server queues job in RabbitMQ/Redis and immediately returns '202 Accepted' with header: 'Location: /api/v1/jobs/job_99'.
3
Client polls 'GET /api/v1/jobs/job_99' until status changes from 'PENDING' to 'COMPLETED'!
Code Implementation Example
http
HTTP/1.1 202 Accepted
Location: /api/v1/jobs/job_99
Content-Type: application/json
{
"jobId": "job_99",
"status": "PROCESSING",
"estimatedTimeSeconds": 45
}💡HTTP 202 Accepted response providing job location polling URL.
🎯 Interview Key Takeaway
Use HTTP 202 Accepted with a Location header for long-running operations to allow clients to poll job progress asynchronously.
#202 Accepted#Async Request-Reply#Background Jobs#Intermediate
Back to all REST APIs & Web Services Questions→