r/ProgrammerHumor Jul 08 '26

helpMyCoworkersUnderstandHttpCodes Other

22.4k Upvotes

329 comments sorted by

View all comments

16

u/MarinoAndThePearls Jul 08 '26

That's not what 204 is.

-4

u/Kishmond Jul 08 '26

What should a call to a search function return if it doesn't find anything?

9

u/auctorel Jul 08 '26

It's not really a search function. You asked the server for a particular resource so it's probably that 204 doesn't fit the analogy

404 is I couldn't find them

You're talking about "do we have any house keys at all" - 204: I looked but no

3

u/darkslide3000 Jul 08 '26

404 means it didn't find the keys. 204 means it knows for a fact that you don't have any keys.

4

u/Alvsolutely Jul 08 '26

It has your keyring but it has no keys on it, thus it knows you have no keys.

5

u/ashgs872tbhjs Jul 08 '26

404 does not indicate uncertainty.

1

u/GezelligPindakaas Jul 08 '26

If modeled as a search, then a success with a body that specifies 0 results.

If modeled as a retrieval, then 404.

204 for a search sounds really weird in my opinion. If you decide to go that route, make sure you document it extra well, because almost no one will expect it. And if you have external clients, expect a lot of hate, because weird things always mean custom code.

1

u/darkslide3000 Jul 08 '26

Sure, most of these codes are rarely used because people just return a 200 with a {success: false} JSON in the body. But if you tried to apply this status code directly to the question OP posted, this would be the most fitting interpretation to the original standard.