HTTP status code for resource that is not available yet

yose93

I have a DB table with a report_url column. As soon as a backend done with filling and storing a report it fills that column with S3 link. If the report was not yet stored, the column value is NULL by default. I also have Pyramid API where an endpoint is declared returning Response with body of report content. So, whenever the user makes request, according controller will be fired to get the report link and download the file and return it to user. However, if report is not done yet (report_url is NULL), I need to inform the user somehow. In this case front-end should receive HTTP status 400, but I have not figured out if this fits best. Or maybe 503 fits better here?

Matthias

Have a look at available http status codes.

What you probably want is 404, specifically because of this line:

In an API, this can also mean that the endpoint is valid but the resource itself does not exist.:

Full description:

404 Not Found

The server cannot find the requested resource. In the browser, this means the URL is not recognized. In an API, this can also mean that the endpoint is valid but the resource itself does not exist. Servers may also send this response instead of 403 Forbidden to hide the existence of a resource from an unauthorized client. This response code is probably the most well known due to its frequent occurrence on the web.

If the server is working on getting the report, 102 gets an honorable mention:

102 Processing (WebDAV)

This code indicates that the server has received and is processing the request, but no response is available yet.

it's not part of the standard, it's an extension, WebDAV.

400 status codes are used to let the user know something they did is not working. 500 status codes are used when something is going on with the server. That's how I understand it anyway.

In that way, if this is a "normal" execution of the API/program, perhaps a 200 status code would do just fine. E.g. just define the endpoint to return {"report_url": null} if it isn't ready, otherwise {"report_url": "an actual url"} and then give 200 in each case. And the receiving party handles it depending on if it is null or not. The pro of this method is, now the user can know that it is definitely a proper endpoint (and not an url typo, which would also give 404). However, you could make your own 404 page saying "report is not ready" or "report does not exist" for example. The con of this 200 method is some speed penalty since you have to send an unnecessary response body.

Disclaimer: I am not a web/http expert at all.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Http REST status code for Resource Available and Not Available

what should be HTTP status code if resource is not available for requested action?

Expected HTTP status code for an action on a disabled resource

Tomcat 8 Http status 404 The requested resource is not available

HTTP Status 404 - The requested resource (/BookStore/index.html) is not available

for a CSS File --> http status 404 - the requested resource is not available

HTTP status 404 the requested resource is not available while opening HTML page

Java Servlet, http status 404, The requested resource is not available

HTTP Status Code 404 or 501 when Operation is not supported by a Resource in REST

how to get Http status code from $resource request

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

Redirection error in spring MVC (http status 404 the requested resource is not available jsp )

HTTP Status 404 - The requested resource is not available. A simple servlet authentication system

HTTP status code to status message

HTTP status code 406 appropriate for "Content not available in your country"? If not, what's appropriate?

HTTP Status Code for Captcha

Http status code for Exceptions

Custom HTTP status code

Http status code return

Incorrect HTTP Status code

switch for http status code

HTTP status code 302

HTTP status code for PUT

Which HTTP status code to use in a REST API if the resource doesn't exist when POSTing a subresource?

What HTTP status code should I return for POST when no resource is created?

What's an appropriate HTTP status code for "requested resource isn't found"?

No 'Access-Control-Allow-Origin' header is present on the requested resource + The response had HTTP status code 401

Python Zeep - HTTP status 415 (no content available)

HTTP and REST: Are Status Codes Relevant to the Request, or the Resource?