Kirk Ouimet
Kirk Ouimet

Reputation: 28364

Handle No Items Found When Getting a List of Items in REST

This is more of a best practice question, but some of you may have some insight on the possible repercussions here. Let's say I call:

GET /v1/items/

and no items are found.

Should I return:

  1. Just 404
  2. 200 with an empty array
  3. 404 with an empty array
  4. ?

Upvotes: 0

Views: 101

Answers (1)

techuser soma
techuser soma

Reputation: 4877

Depends on how you want to handle the response. I would go for 200 with an empty array, indicating that the REST call succeeded but no matches found. This would be helpful for the layer that consumes the deerialized response.

If you are relying heavily on the HTTP status codes for downstream processing/error handling/error messages then 404 is fine. This is helpful if the request is often performed via a browser also. And also this would be a purist approach.

I do not see any added value for the third option.

Upvotes: 2

Related Questions