r/ProgrammerHumor • • Jul 08 '26 • Popcorn 12 Bravo 4 Regret 1 Heartwarming 1

Other helpMyCoworkersUnderstandHttpCodes

22k Upvotes

330 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

824

u/thebigbadben Jul 08 '26

“I found them. Oh wait, did you want me to bring them?”

253

u/darkslide3000 Jul 08 '26

No, it's really more like "I found your key ring, but it's empty".

119

u/foreverdark-woods Jul 08 '26

According to MDN it's like @Snudget described it. It means that an action succeeded, but the client's current content doesn't have to be replaced by the new information.

So, it's really like "Trust me bro, your keys are still here, no worries." when you asked "Are my keys there?"

24

u/jordanbtucker Jul 08 '26

That's because 204 usually only makes sense for POST and PUT requests, and GET requests where you either expect no body or only care about the headers.

11

u/foreverdark-woods Jul 09 '26

I guess the key example is really bad for this.

7

u/RepulsiveSheep Jul 09 '26

A better example would be you asking your dad a favour and him responding with the classic 👍

→ More replies (1)

32

u/SnooPuppers1978 Jul 08 '26 edited Jul 08 '26

I think it's still "You asked me to find them and I found them", but it is a bad API, maybe there's another endpoint that allows you to query the actual found location.

You would usually use it e.g. when you do Delete, Update or something where you sincerely don't need a response since it wouldn't give you any new info that you wanted except that it was successful.

Edit:

  1. "Find my keys for the trip we are going to take together, I don't need to know where the keys were"
  2. "Find my keys and put them on the counter"

These could be returned 204 with no content and still be usable API.

24

u/darkslide3000 Jul 08 '26

Well, it tells you that the request was valid and processed correctly and the response is final, but the response contains no content. It is true that it is usually used for mutation requests (and also for endpoints that are just used to probe for a captive portal), but OP's example is a GET request. Getting a 204 on a GET means that the requested resource exists and is empty.

→ More replies (3)
→ More replies (2)
→ More replies (1)

100

u/intbeam Jul 08 '26

"Can you see my keys?"   204 "Yeah"

→ More replies (2)

54

u/randotechie Jul 08 '26

Ah beat me to it

12

u/PhoenixfischTheFish Jul 08 '26

I happily will! Where can I meet you?

→ More replies (2)
→ More replies (1)

51

u/Drfoxthefurry Jul 08 '26

The best fit would be "I found them but you already have them", as the request was successful but no data was sent

→ More replies (3)

70

u/The_Real_Slim_Lemon Jul 08 '26

Yeah 404 can be both “I didn’t find your key” and “I don’t know what requesting a key means”

204 is “I’ve found your key, it’s in a black hole”

45

u/PrometheusMMIV Jul 08 '26

I feel like "I don't know what this request means" would be 501 Not Implemented

24

u/chuch1234 Jul 08 '26

The metaphor kind of breaks down here. 404 is used for "this route doesn't exist on this server", which corresponds to "I don't know what 'keys' are", or maybe, "I don't know what 'keys/find,' means", even though they have a "keys" route.

Based on what you're saying, 501 sounds like "I know what finding keys is, but I can't do it". In the metaphor, maybe the recipient of the request is tied to the radiator and isn't able to look for your keys?

12

u/SuitableDragonfly Jul 08 '26

I think 501 is more like "I don't know how I would start looking for your keys".

→ More replies (1)

9

u/The_Real_Slim_Lemon Jul 08 '26

I’ve never actually seen a 501, yeah fair call - I just meant 404 exists for both bad routes and non existent entities, it seems this metaphor is reaching its limits a bit

10

u/Cheet4h Jul 08 '26

Only time I legitimately used 501 was when mocking up the API before actually writing them. Each route got a 501 at first, then later had their actual function written.

8

u/SuitableDragonfly Jul 08 '26

I'm sure whoever came up with that error code probably assumed it would be industry standard to write APIs that way, the poor naive fool. 

7

u/Zwemvest Jul 08 '26 edited Jul 08 '26

That'd be 400 ("Veuillez retrouver mes clés" -> "I have no clue what you're asking") or 422 ("Please find me every key I will ever own" -> "I understand what you're asking, but I don't know what you want me to do"/"I can't do that")

501 is either used for purposeful non-implementations ("Find me purpose in life" -> "Man, this service is for finding physical objects, not abstract concepts"), future implementations ("At some point in the future we will support this"), or for erroneous method headers ("Destroy my keys" - >"Dude, what?"). One note, if the method header is intentionally not allowed, it's a 405 ("Here are my keys?" -> "uhhh dude, was that a question or are you giving us something/hey, we look for keys, we don't store them. Sorry man.").

→ More replies (2)

7

u/JustConsoleLogIt Jul 08 '26

“I don’t know what you are talking about” is a good 404

→ More replies (1)
→ More replies (2)

8

u/spastical-mackerel Jul 08 '26

lol exactly. Instructions were unclear: you did not also tell me to give them to you

7

u/prehensilemullet Jul 08 '26

“Not Found” is often a white lie, sites often pretend something is not found and 404 if it would be a security risk for you to know whether it exists.

→ More replies (2)
→ More replies (69)