liveBook · Manning

HTTP 202 Accepted

As explained in The Design of Web APIs, Second Edition

202 Accepted is the HTTP status indicating that a request has been accepted for processing but the processing may not yet be complete.

HTTP 202 Accepted acknowledges a request that has been accepted for processing, even though the work may not be complete. Use it when execution is deferred or will take too long to finish before responding; acceptance is not a promise that the work has already succeeded. section 4.5.4 section 14.7.1

Choose the response to match what happens to the request:

  • Return 202 Accepted when valid work will be processed later, such as during planned downtime. section 14.2.3
  • Return 503 Service Unavailable with Retry-After when the service cannot accept the request and should tell the consumer when to retry. section 14.2.3
  • For an instantaneous deletion, use 204 No Content when it is complete and returns no data; 202 would imply it has not yet been executed. section 4.5.4

Defer a bank transfer

During a banking holiday, accept a valid transfer request for later processing and return 202 Accepted with status DELAYED and a processingDate of January 2, rather than the usual 201 Created. This avoids an error response, but requires checks before execution and accepts the risk that the balance may be insufficient when the transfer runs. section 14.2.3

Track a long-running simulation

For a simulation that may take an hour, return 202 Accepted with its status and a Location header pointing to /simulations/12345. The consumer can poll that URL for IN_PROGRESS or DONE. Progress, estimated completion time, and Retry-After guidance can help the consumer decide when to poll again. section 14.7.1 section 14.7.1

How The Design of Web APIs, Second Edition covers it

How deep it goes
Explains deferred acceptance, response metadata, and polling, while contrasting immediate completion and service unavailability.
Examples
Uses delayed bank transfers during a holiday and on-demand stock-market stress simulations lasting up to an hour.
What you can do after
Apply it by returning an operation status and Location header, then polling the resource and using progress estimates to adjust call frequency.
How it connects
Connects HTTP 202 Accepted with HTTP 503 Service Unavailable, Retry-After, polling, and HTTP 201 Created.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Design of Web APIs, Second Edition. The section links point to the parts of the book it draws on.