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

Improve Router/Resource interaction #6

Closed
Dashron opened this issue Apr 1, 2012 · 5 comments
Closed

Improve Router/Resource interaction #6

Dashron opened this issue Apr 1, 2012 · 5 comments

Comments

@Dashron
Copy link
Owner

Dashron commented Apr 1, 2012

When a resource performs a route, it should strip the resources uri from the route and pass it to the router.
This should also happen when chaining through into child routes.

eg.

var zaft_resource = { uri : '/' , dependencies : ['user']};
var user_resource = { uri : 'user/' };

zaft_resource.route('/user/123');
//pull off the forward slash for the zaft_resource, so we are routing based on user/123
//check all children for a match
// if found
// pass into appropriate resource (in this case it's the user resource because 'user/123' is prefixed by the user_resources uri of 'user/'
// Go back to top, which will pull off 'user/', so we are simply routing based on the uri of '123'. This will not find any resources, so it goes to the routes and locates the route for /\d+/
// if not found, check all routes for a match

We might want this to be configurable, because it's a slightly odd logic flow.
The intent is to widen the use of common modules, by abstracting away the full uri.

Having a user module with the following routes would enable it to be used on a wider range of sites
/// : post = add, delete = remove
/\d+/ : get = read, put = update
/\d+/posts/ : get = read all posts, post = assign a post to a user

And then users can just change the uri config, and enable it across all sorts of sites.

@Dashron
Copy link
Owner Author

Dashron commented Apr 1, 2012

"/\d+/posts/" might be a bad example here. Is there a way to provide extra data down into a route? Or maybe we need a way to have routes redirect within the router.

Basically, should it be "/\d+/posts/" or should the user module depend on the blog_posts_resource, which uses the posts uri, and has a "///" route.

@Dashron
Copy link
Owner Author

Dashron commented Apr 1, 2012

maybe this isn't best.

Look into building a way to generate child resources? or mixed resources.
so the user resource would depend on a "PostUser" resource, which is an extension of the post resource with brand new routes, each of which expect some form of user information to be provided to the route.

@Dashron
Copy link
Owner Author

Dashron commented Apr 2, 2012

Added research tag. This should be decided on after some common use cases have been developed (a more advanced example resource, and some sub_example resources)

@Dashron
Copy link
Owner Author

Dashron commented Apr 4, 2012

13bed9e

This uses the technique of stripping out the resource uri on each request.
This is nice because it allows me to move the entire site up into a subdirectory just by changing the example resources uri.

Maybe the right technique is a combination.
Use the uri strip technique, but still provide a way to depend on a core resource, with a separate routing mechanism.

eg.

example depends on user and blog_post
user depends on blog_post(blog_user_routes)

/user/5/posts
becomes user/5/posts after the example uri is removed
becomes 5/posts after the user uri is removed
?becomes 5 after the /posts uri is removed?
?user 5 is loaded, and then we route again into /posts, providing user 5 as a parameter?

The last one seems like the best technique, but I'm not sure how intuitive that would end up. This all seems way too complicated. For the moment maybe we keep this uri stripping thing in as a test, and just assume people use one level of hierarchy. it will be more like the traditional controller scheme that people are used to.

@Dashron
Copy link
Owner Author

Dashron commented Apr 6, 2012

Currently, the example uses an empty uri, and then the first level sub routes have /user/, /posts/ etc. This is useful for routing from within a resource.

@Dashron Dashron closed this as completed Apr 6, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant