Reputation: 1219
I thought that a single resource can be identified by many URLs.
From:
A resource in a hypermedia API is probably better thought of representing the API response rather than the underlying model instance, as the response is obviously not the same from these two URLs
But above quote suggests that in REST each URL always identifies a different resource ( thus two URLs can never identify the same resource ). Reason being that a resource in a hypermedia API is better thought of as representing the API response rather than the underlying model instance, and considering that API responses from different URLs are definitely not identical, the conclusion is that two URLs can never identify the same resource.
Would you agree that in REST a resource should be thought of as representing the API response and as such two URLs can never identify the same resource?
Thank you
Upvotes: 2
Views: 731
Reputation: 8650
tl;dr no - two URIs can refer to the same resource
There is nothing wrong with a 'resource' being represented by multiple URIs, or URIs 'linking' to a virtual resource that does not exist until a user GETs it and the server calculates what that value should be.
example, /schools/5/pupils/thecoshman
would be the same as /pupils/thecoshman
, it's me, it's just the first UIR lets you know (well, presume) I am in 'school 5'. Ideally though, the URI should be returned as the shortest form, so I'd say the second one should represent me.
Why would you get that longer one? Well, what if you called /schools/5/pupils
? That would return a list of 'pupils' in that school (though probably as more than just a list like this).
/schools/5/pupils/thecoshman
/schools/5/pupils/bckpwrld
Though as I said above, you should probably link to the shortest (in terms of hierarchy) URI for the resource, so drop the '/schools/5' prefix. The users just got this data from /schools/5/pupils/.
Upvotes: 2