What is the most appropriate HTTP status code to give to a client to mean "your request is fine, but it is still in progress; check back shortly in the exact same place."
For example, say the client submits an initial request to start a heavy query, and the server immediately returns a URL that the client can poll periodically for the result. In the case the client calls this URL before the job is completed, what is the most appropriate HTTP status code to return?
202 Accepted would be my first impulse. Is this the best one, or is there a better one that is more idiomatic for this purpose in REST interfaces?
HTTP response status codes indicate whether a specific HTTP request has been successfully completed. Responses are grouped in five classes: Informational responses ( 100 – 199 ) Successful responses ( 200 – 299 )
The HTTP status code 500 is a generic error response. It means that the server encountered an unexpected condition that prevented it from fulfilling the request. This error is usually returned by the server when no other error code is suitable.
We tend to get -1 status codes when there are network issues or connection problems, so we display the user a network problems page in those cases.
The HTTP 201 Created success status response code indicates that the request has succeeded and has led to the creation of a resource.
To me, 202 Accepted would be the best way to go.
See the documentation on the W3C website.
10.2.3 202 Accepted
The request has been accepted for processing, but the processing has not been completed. The request might or might not eventually be acted upon, as it might be disallowed when processing actually takes place. There is no facility for re-sending a status code from an asynchronous operation such as this.
The 202 response is intentionally non-committal. Its purpose is to allow a server to accept a request for some other process (perhaps a batch-oriented process that is only run once per day) without requiring that the user agent's connection to the server persist until the process is completed. The entity returned with this response SHOULD include an indication of the request's current status and either a pointer to a status monitor or some estimate of when the user can expect the request to be fulfilled.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With