Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I choose a HTTP status code in REST API for "Not Ready Yet, Try Again Later"? [closed]

I'm developing a RESTful API in which http://server/thingyapi/thingyblob/1234 returns the file (aka "blob") associated with thingy #1234 to download. But it may be that the request is made at a time the file does not exist in the server but most definitely will be available at a later time. There's a batch process in the server that generates all the blobs for all the thingies. Thingy 1234 already exists and its data, other than the blob, is already available. The server hasn't got to generating thingy 1234's blob yet.

I don't want to return 404; that's for thingies that do not exist. This is a thingy that exists, but its blob hasn't been generated yet. Kinda like a YouTube video that's "processing." I don't think redirection codes would be proper either; there's no "other" URL to try.

What's the correct HTTP status code to return in such a case?

like image 654
JCCyC Avatar asked Mar 20 '12 20:03

JCCyC


People also ask

Which HTTP status codes should retry?

HTTP status codes and the error message can give you a clue. In general, a 5xx status code can be retried, a 4xx status code should be checked first, and a 3xx or 2xx code does not need retried.

What status code will I get if the API is not available?

404 Not Found This is by far the most common HTTP status code you can get. It indicates that the URL you used in your request doesn't exist on the API server, or origin server. While this is a 4XX error, which usually means something on the client-side is wrong, this can also indicate a server problem.

How do you set a status code in HTTP response?

Methods to Set HTTP Status Code Sr.No. This method sets an arbitrary status code. The setStatus method takes an int (the status code) as an argument. If your response includes a special status code and a document, be sure to call setStatus before actually returning any of the content with the PrintWriter.


1 Answers

I suggest 202 - Accepted. From the documentation:

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

like image 69
matsev Avatar answered Sep 19 '22 13:09

matsev