logoalt Hacker News

brightballyesterday at 10:55 PM3 repliesview on HN

Yea, empty response at a valid path. Isn’t 204 the code for it?

Lots of REST libraries that I’ve used treat any 400 response as an error so generating a 404 when for an empty list would just create more headaches.


Replies

HumanOstrichtoday at 1:46 AM

Libraries that automatically throw errors for status codes in the 400 and 500 ranges are pretty obnoxious (looking at you, axios). It adds unnecessary overhead, complexity, and bad ergonomics by hijacking control flow from the app.

Responses with status codes in the 400 range are client errors, so the client shouldn't retry the same request. So a 404 is appropriate despite how annoying a library might be at handling it. Depending on which language/ecosystem you are using, there are likely more sane alternatives.

show 2 replies
sk5tyesterday at 11:52 PM

204 might be acceptable if you aren’t returning an entity body to describe what is missing, but do wish to indicate the request was successful.

burnishedtoday at 12:43 AM

I think the author is comfortable creating headaches for people tacking query strings onto URLs