Most appropriate HTTP status code for work in progress

What is the most appropriate HTTP status code to let the client mean that "your request is ok but it is still ongoing, quickly return to the same place."

For example, let's say a client sends an initial request to start a heavy request, and the server immediately returns a URL that the client can periodically query for the result. If the client calls this URL before the job is completed, what is the most appropriate HTTP status code to return?

Accepted would be my first impulse. Is this the best, or is there a better one that is more idiomatic for this purpose in REST interfaces?

+6
source share
1 answer

To me, 202 Accepted would be the best way.

See the documentation on the W3C website.

10.2.3 202 Accepted

The request has been accepted for processing, but processing has not been completed. The request may or may not end up as it may be prohibited when processing actually takes place. There is no way to resend the status code from such an asynchronous operation.

Answer 202 is intentionally not consistent. Its purpose is to allow the server to accept a request for some other process (possibly a batch-oriented process that starts only once a day) without requiring that the connection between the user agent and the server be maintained until the process is completed. The object returned with this response SHOULD include an indication of the current status of the request and either a pointer to the status monitor or some estimate when the user can expect the request to be completed.

+16
source

All Articles