Using REST principles, 404 seems to be used to indicate that an entity does not exist. However, how can clients distinguish this case from hitting an incorrect endpoint altogether?
I want to distinguish between, "you came to the right endpoint, but that entity doesn't exist" and "you're not at the right endpoint". Technically, this can be distinguished using other response codes, custom headers, etc. but I am mainly concerned with REST best-practices in this area so clients are as simple and standard as possible.
I believe the determination of the correct endpoint is the sole responsibility of the REST client. (Of course, an endpoint resolution service could be easily implemented.) A 404 error just means that this particular endpoint doesn't host that particular entity.
Nothing in RESTful design requires a server to know if a client is interacting with the "correct" host.
you came to the right endpoint, but that entity doesn't exist
If there is no resource identified by the URL, how could it be the right endpoint? The only possible scenario I could think of is that the entity has been deleted, in which case 410 Gone is the correct response.
Remember that if you are following RESTful principles then the URL should have been provided by the server and if so, why is the server handing out invalid URLs?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With