DEV Community

Discussion on: 404 status code! Really?

Collapse
 
rafaacioly profile image
Rafael Acioly • Edited

Marco, what i usually do is

If the request came on a list endpoint and there's no content i return 200 with a empty list, if the request is for a single record and the record doesn't exist i return 204.

Normally my "pagination" responses retrieve another useful data as well like "next_page", "count" and etc, so it makes easy for validation if the response is "200".

Thread Thread
 
mdamaceno profile image
Marco Damaceno

An empty list is no content as well. Why not use 204 for it?

Thread Thread
 
pchinery profile image
Philip

If you have no items for the list, returning an empty list will yield the full available content. Maybe you will also add some metadata (e.g. total number of entries) to support pagination. Your consumer will not have to treat this differently from a filled list. When requesting a single item that does not exist, users would have to examine the content and see if they can work with it. And from my experience: if you start seeing surprising responses, the trust in the responses from this system drops rapidly.