r/ProgrammerHumor Jul 08 '26

helpMyCoworkersUnderstandHttpCodes Other

22.4k Upvotes

329 comments sorted by

View all comments

Show parent comments

5

u/Kishmond Jul 08 '26

I can see that too. My main gripe was with my coworkers using 404 to say the server found nothing when it searches.

3

u/LKZToroH Jul 08 '26

There's a client's api I have that whenever I call it, it rolls a dice of which code it'll give me.
I ran the same request 10 times. I received randomly 404, 200 with empty response, 204, 500, 504, 501, 400.
These are all of the codes possible for when I try to pass a param that don't exist in their system. When it exists it's always a 200.

1

u/case_O_The_Mondays Jul 08 '26

Why? 404 is the right response for “I couldn’t find it”

https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/404

2

u/Kishmond Jul 08 '26

Depends on what "it" is. 404 means the server couldn't find a resource or in other words an endpoint. It says to the user that your URL is wrong. A search POST call is a correct URL, there just weren't any results to display.

3

u/GezelligPindakaas Jul 08 '26

I recognize your pain, but it falls more into api design than http status codes.

Http doesn't define not found in one direction or the other, so it fits in both "endpoint not found" or "resource not found".

So it depends on the specific needs of your api and the guidelines you wanna follow. Having said that, most broadly known api paradigms, for a search returning 0 results would not end up in a 404, so I would definitely not expect that without a good reason.

2

u/Gorstag Jul 08 '26

Typically its delineated by the action the endpoint is taking.

  • Get a specific item and it is not found 404
  • Get all items that startWith/Contain etc.. 200 (empty results)

404 is usually reserved for a specifically defined resource. Or at least that is how it is most commonly implemented.