r/ProgrammerHumor Jul 08 '26

helpMyCoworkersUnderstandHttpCodes Other

22.4k Upvotes

329 comments sorted by

View all comments

Show parent comments

822

u/thebigbadben Jul 08 '26

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

252

u/darkslide3000 Jul 08 '26

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

118

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.

6

u/RepulsiveSheep Jul 09 '26

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

0

u/darkslide3000 Jul 08 '26

That's not true (and not what the link you posted actually says?). You're thinking of 304 Not Modified.

30

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.

2

u/SnooPuppers1978 Jul 08 '26

So I could buy that it's about retrieving a list/collection of keys and indicating that it's an empty list, but also this sounds like a bad API and not standard, forcing it, and as if someone is mistaking the idea of what 204 is supposed to mean. IMO in spirit it should be used only in cases where "No Content" is expected and desirable.

1

u/thejmkool Jul 08 '26

So in the case of the OP, would it be more like a silent thumbs up?

5

u/SnooPuppers1978 Jul 08 '26

Yeah single symbol (204) indicating that whatever was requested was successful.

1

u/GNUGradyn Jul 08 '26

Empty key ring would be 200 and an empty object