Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Yes! This is absolutely one of my biggest pet peeves.

A 404 should not be shown on a valid path with an empty result. That’s exactly what 204 is meant for.

Moreover, a 404 in many REST clients will bubble up an error in the application code because it thinks there’s something wrong (you’re trying to reach something in the wrong place). That’s not the case for an empty result, any more than an empty list is an error.



From the perspective of an HTTP server, a resource either exists, or doesn't. There's no concept of a "valid path".

If you do GET /a/b/c, if /a/b/c exists you get a 200, if it doesn't you get a 400 (and if you're not allowed to access it you get a 401 or 403 depending on some other details, and if the server has a problem while replying you get a 500 etc).

This is a very important concept about what an HTTP URL means, and how it is understood by HTTP servers and middle-boxes (caches, proxies etc).


That’s just it though, the resource does exist. The resource is the API to retrieve a result.

The result being empty doesn’t mean the resource doesn’t exist, in the context of an API.


> That’s just it though, the resource does exist. The resource is the API to retrieve a result.

That is not true if the API is RESTful - in that case, the API is the resource. An item with the requested URL either exists or doesn't. If it doesn't, then return 404 and (if possible) give some more information.


Reading the spec, that's definitely not what 204 is meant for.

https://httpwg.org/specs/rfc7231.html#rfc.section.6.3.5

> The 204 (No Content) status code indicates that the server has successfully fulfilled the request and that there is no additional content to send in the response payload body.

I don't see how that could be intepreted to mean "You have requested a resource which does not exist". It's intended for use cases like "Your request to save the file has been received, no further content will be sent".

Or am I misreading the spec?


I don't know if it's still true, but back in the day returning 204 would mean the browser page won't refresh. It was one of the way to send data to server without page reloading.

Sending 204 with body definitely break the spec.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: