liberator
liberator copied to clipboard
Hierarchical URIs
Is there are reasonable way using liberator resources to incrementally validate hierarchical URIs? Regardless of the HTTP and other attributes of the HTTP request, if the parent resources don't exist in a hierarchy, it is reasonable to return a "Not Found" before processing the request at the terminal resource.
Example: A PUT request to /foos/123/bars/876
should fail with "Not Found" if the ancestor resources (foos
, foos/123
, foos/123/bars
) do not exist.
It would be helpful if the infrastructure of liberator could be applied to short-circuiting requests to resources whose ancestors do not exist.
This would depend on the data model, right? If the parent entity is eagerly loaded with the exists?
check on the parent resource, and if that could be passed through to the child resource, because the child is contained within the parent, that would be useful. If, however, the query is on the child by parent-id and child-id, then the extra query by the parent resource would be unnecessary.
Agreed. The short-circuiting should be opportunistic so as to avoid a mandatory double query penalty.
I guess my point is that in my second example, it would be nice to still define the relationship within Liberator, but also not have the unnecessary double query. Maybe that's what you mean by "opportunistic"?
Yep. If the parent doesn't exist, and it's cheap to determine and/or beneficial to query independently, then allow it. But don't require it.
I have thought about this before and I did not come to a conclusion yet. I think this would required deeper integration with a routing library to make effective use of the parent-child relationship. But in the end, all what a liberator resource does to query the existence of a resource is to call :exists?
, so you can build some infrastructure fns that help with that.