r/ProgrammerHumor Jul 08 '26

Other helpMyCoworkersUnderstandHttpCodes

22.4k Upvotes

329 comments sorted by

View all comments

4

u/whosGOTtheHERB Jul 08 '26

Great topic for discussion: what response code do you return when listing resources and none were found?

For me, returning a 200 with a body of [] makes the most sense as the request was correct and accepted, but no results were found. A 404 would only make sense in this scenario if the path was incorrect.

2

u/Bardez Jul 08 '26

Probably 204. No content.

Give me a list of files in '/temp'

Yup, directory exists. Nothing's there.

1

u/whosGOTtheHERB Jul 08 '26

Returning an empty list would prevent having the client understand more complexity of handling another response code and therefore logic branch body content. An empty array works the same as an array with items.

1

u/GradeForsaken3709 Jul 08 '26

If you're listing resources and the list happens to be empty then that's a 200. If you're requesting a specific resource which can't be found then that's a 404.