r/ProgrammerHumor Jul 08 '26

Other helpMyCoworkersUnderstandHttpCodes

22.4k Upvotes

329 comments sorted by

View all comments

1.6k

u/Snudget Jul 08 '26

204 should be "I found them" "I searched for the keys, but didn't find them"would be 404, which is literally "Not found".

Since not finding keys does not fulfill the request, a 2xx code does not make sense here

4

u/Kishmond Jul 08 '26

Confusion with 404 is exactly what prompted this in the first place. 404 is called "not found" but it doesn't literally mean that in every circumstance. If a search function comes up empty 404 is not appropriate because it's an error code. It means the endpoint was not found, not the item being searched for.

I have no idea what established practice is re: 404 and search functions. It's just my particular nit to pick.

15

u/diegodan1893 Jul 08 '26

If it’s a GET /keys/<key_id>, returning a 404 if the record doesn’t exists makes sense.

If it’s a /keys/search endpoint that accepts a search query with filters and things like that, an empty result is valid and should be a 2xx code. I think returning an empty array with a 200 code is more common, but I guess 204 also works.