Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTP Status 202 - how to provide information about async request completion?

What is the appropriate way of giving an estimate for request completion when the server returns a 202 - Accepted status code for asynchronous requests?

From the HTTP spec (italics added by me):

202 Accepted

The request has been accepted for processing, but the processing has not been 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.

Here are some of thoughts:

  • I have glanced at the max-age directive, but using it would be abusing Cache-Control?
  • Return the expected wait time in the response body?
  • Add an application specific X- response header, but the X-headers was deprecated in RFC 6648?
  • Add a (non X-) specific response header? If so, how should it be named? The SO question Custom HTTP headers : naming conventions gave some ideas, but after the deprecation it only answers how HTTP headers are formatted, not how they should be named.
  • Other suggestions?
like image 617
matsev Avatar asked Feb 12 '13 12:02

matsev


People also ask

How do I fix status code 202?

What can I do to resolve the issue? Answer: The most likely cause of error code 202 is a communication issue between the Rockstar update servers and your internet service provider. Changing the DNS server for your internet connection may help resolve this issue.

When should I use HTTP Status 202?

HTTP Status 202 indicates that the request has been accepted for processing, but the processing has not been completed. This status code is useful when the actual operation is asynchronous in nature.

What does the response code 202 and 204 mean?

200 OK. 201 Created. 202 Accepted. 203 Non-Authoritative Information. 204 No Content.

What is the difference between 200 and 202?

200 OK means that the request has succeeded and the processing of our request is done. The response is the final payload and the service will not take further actions. 202 Accepted on the other hand means that the request have been accepted for processing, and the service will now start.


2 Answers

Definitely do not abuse existing HTTP headers for this. Since it's your own server, you get to define what the response looks like. You can (and should) pick whatever response works best for the intended recipient of this information and return the actual information in the response body.

For example, if you are only interested in displaying a human-readable message then you could return text/plain saying "Your request is likely to be processed in the next 30 minutes.".

At the other end of the spectrum, you might want to go all the REST way and return application/json, perhaps formatted like this (I totally made this up on the spot):

{   "status": "pending",   "completion": {     "estimate": "Thu Sep 08 2011 12:00:00 GMT-0400",     "rejected-after": "Fri Sep 09 2011 12:00:00 GMT-0400",   },   "tracking": {     "url": "http://server/status?id=myUniqueId"   } } 
like image 136
Jon Avatar answered Oct 02 '22 17:10

Jon


You can use the Location header to specify the URL of the status monitor. Things like current status and estimate can either go in custom headers (which noone but your own software would use), or in the response body (which a web browser would display to a user, at least).

like image 21
Remy Lebeau Avatar answered Oct 02 '22 18:10

Remy Lebeau