Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to distinguish 404 between entity doesn't exist and incorrect endpoint?

Tags:

rest

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.

like image 842
jnorris Avatar asked Jun 04 '10 19:06

jnorris


2 Answers

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.

like image 56
maerics Avatar answered Oct 19 '22 00:10

maerics


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?

like image 31
Darrel Miller Avatar answered Oct 18 '22 23:10

Darrel Miller