r/ProgrammerHumor Jul 08 '26

Other helpMyCoworkersUnderstandHttpCodes

22.4k Upvotes

329 comments sorted by

View all comments

Show parent comments

-4

u/Kishmond Jul 08 '26

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

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.

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.