liberator icon indicating copy to clipboard operation
liberator copied to clipboard

Hierarchical URIs

Open cch1 opened this issue 8 years ago • 5 comments

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.

cch1 avatar Feb 05 '17 04:02 cch1

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.

jeremyheiler avatar Dec 21 '18 21:12 jeremyheiler

Agreed. The short-circuiting should be opportunistic so as to avoid a mandatory double query penalty.

cch1 avatar Dec 21 '18 21:12 cch1

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"?

jeremyheiler avatar Dec 21 '18 21:12 jeremyheiler

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.

cch1 avatar Dec 21 '18 23:12 cch1

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.

ordnungswidrig avatar Dec 27 '18 09:12 ordnungswidrig