0

I have an endpoint for a REST API that checks for the existence of a (or a list of) requests.

It can return 200 OK if there is an order in progress

or 404 NOT FOUND if there are no current orders

Creating an availability SLO for this API, I noticed that a high percentage of requests made to this route results in a 404 status code, decreasing the availability percentage.

Is it correct to think that if no request was found, it doesn't mean that resource was not found?

Because it was possible to work on the resource, and what it found was an empty list, in which case the correct return would be 200OK

  • I am very satisfied with the answers of this question: https://stackoverflow.com/questions/30217761/http-200-or-404-for-empty-list?rq=1 – Plinio Fabrycio Sep 09 '22 at 04:17
  • Does this answer your question? [HTTP 200 or 404 for empty list?](https://stackoverflow.com/questions/30217761/http-200-or-404-for-empty-list) – Evert Sep 11 '22 at 02:29

1 Answers1

1

Both 200 OK and 404 NOT FOUND fulfills the HTTP standard. For non existing item resources e.g. /items/1 I would go with 404 for empty collection resources /items/?q=blah I would go with 200 and an empty JSON array, []. In that context I think 404 means that there is no route matching the URI.

As of mixing item resources and collection resources, I think it is a very bad idea. You need to add an if-else to the client and check if the response contains an object or an array. I would rather go with two different URI templates, one for the item and one for the collection.

inf3rno
  • 24,976
  • 11
  • 115
  • 197