Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hierarchical URIs #273

Open
cch1 opened this issue Feb 5, 2017 · 5 comments
Open

Hierarchical URIs #273

cch1 opened this issue Feb 5, 2017 · 5 comments
Labels

Comments

@cch1
Copy link
Contributor

cch1 commented Feb 5, 2017

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.

@jeremyheiler
Copy link
Contributor

jeremyheiler commented Dec 21, 2018

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.

@cch1
Copy link
Contributor Author

cch1 commented Dec 21, 2018

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

@jeremyheiler
Copy link
Contributor

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

@cch1
Copy link
Contributor Author

cch1 commented Dec 21, 2018

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.

@ordnungswidrig
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants