Reputation: 255
How does one define which resource is a top level Rest resource (URI not nested inside any parent)?
My question comes from the fact that, if I take literally the concept of resource hierarchy, I end up getting very long URIs, like 5 or 6 levels deep.
This goes against the REST simplicity principle, and moreover, all of the ids along the chain are unique, so it is possible to simplify/shorten. Also, big REST apis like twitter or facebook, do not follow the hierarchy rule literally.
Upvotes: 2
Views: 812
Reputation: 113232
There is no heirarchy rule in REST.
Indeed quite the opposite: It's a principle of REST that URIs are opaque, and as such the URI <http://example.net/careers/technical/it/computing/programming/webProgramming/asp.net>
conveys no more information from a REST perspective than <http://example.net/fasd12>
.
Note that both these URIs are equally opaque from a REST perspective. A given process (digital or human thought) might interpret the former a particular way, but until the server says otherwise, that interpretation is not going to be correct (there's no way of knowing from looking at the URIs alone that they both identify a web service to help predict the milk yield of a herd of goats).
Where hierarchies come in is:
In the latter in particular, hierarchies can be very useful.
And in this case, having URIs are that are 5, 6 or 14 levels deep are useful if you are modelling a set of resources which have a hierarchical relationship to each other that is 5, 6 or 14 levels deep. And not otherwise.
In this case it doesn't violate any principle of simplicity:
..
as a relative URI reference is very simple, whether it is going from 1 level deep to 0, or 43 levels deep to 42../programming/
as a relative URI reference is very simple, whether it is going from 0 levels deep to 1, or 42 levels deep to 43.Edit:
Conversely, while there's no reason to fear deep hierarchies, there's no reason to feel beholden to them either. If it's more useful to you to have a resource at /a/b/c
include as a composite resource one at /d
then fine. One can also do both, with /a/b/c/d
and /e
both identifying the same resource (having one 301 to the other would result in better cache behaviour and make the relationship explicit).
Upvotes: 3