-
Notifications
You must be signed in to change notification settings - Fork 140
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
url helpers #20
Comments
Are you referring to rails-style route helpers? Along the lines of:
I am working on these, would be happy to style them for better integration into express-resource. Right now I am attaching them as dynamicHelpers, but I haven't worked out the best way to make them available in the controllers. |
kinda yeah. controllers can just use regular modules, no need for helpers really, and most helpers are view related so controllers shouldn't really be using them anyway. |
If we write the functions to construct a route from the resource, those can be useful in both the view and the controller:
It would be nice to get two-for-one, at least if people want it. I think this can be done cleanly by writing a module for the controllers and then a wrapper module for the dynamicViewHelper that people can use if desired, but I am new to this architecture so please "redirect" to your vision. Bigger picture, am I understanding the types of methods you are thinking of, or did you have something else in mind? |
yeah, but it's JS so you'll never have something "clean" like list_path() automatically injected into the scope, you'll have |
this ticket looks like something I am also looking for in relation to a django 'reverse' use I have at the moment, see also https://docs.djangoproject.com/en/dev/topics/http/urls/#reverse Basically in django I have something like:
And later I have something like:
and fullUrl is then basically "http://server:port/baseurl/foo/bar" which I currently return in an existing rest api. Specially important here is that 'my code' would not need to know about server, port or baseurl. Just 'specific-product' and the fact that it expects 2 parameters (version and product). |
yikes! what a verbose way to get a url :s I know what you mean though, rails (and I guess every mvc framework) has similar. |
japj, if I understand you correctly, you are actually using two segments of the path to identify a unique resource (foo+bar), and that is how your example differs from mine, am I right? In normal RESTful routing, you would have So I think you need Correct? I have not looked into the guts of express-resource enough to know if this is a major change or not. If express-resource can accommodate it reasonably, then I suspect I could maneuver the URL generation code I have in mind to handle it as well. TJ? |
OK, I have this a first pass, please have a look at donedotcom@cd8e08c (and donedotcom@544123a, I missed the test resources the first time around). I've made a few design decisions that I am happy to take other directions on so that we can get this integrated: I am still new to JS so please feel free to aggressively comment on implementation decisions. |
Additional changes, see the head of my fork. Bug fixes and also I renamed functions to be _path for consistency when I integrate into the dynamicViewHelper -- it turns out to be a bad idea to have functions like 'users' injected into the view scope as they can often be the same name as local objects defined by the controller. |
Dynamic View Helpers implemented here, not sure where/if to include them in express-resource, please advise. If nothing else, maybe we can make them an example. |
sorry for the late reply, but I have been a bit busy with work. |
Excellent, any time you can get to it. On Wed, Jul 13, 2011 at 2:43 AM, japj <
|
Regarding /resource_name/:id/sub_resource_name/:sub_resource_id I think that correctly resembles how I should have modeled my rest api. (I will need to update my server and client to correctly behave that way, but it makes sense to have it behave as nested resources). For 'id' your example currently uses integers. Would this also work when 'id' is actual a word or something like "192.168.1.2"? I note that the path functions expect an object with 'id' to be passed to it. However since action information is provided in the req.params, it might be usefull if one can do: app.resource.path.forum_thread(req.params.forum, req.params.thread) Last question, since I'm not entirely familiar with how this is done in nodejs: where would one get the server/ip part for the url? i.e. when app.resource.path.forum_thread(forumObj, threadObj) returns '/forums/5/threads/50', where does one get "http://servername:port/" from to combine it to a full url? |
|
With req.params.forum I meant the routing behaviour from http://expressjs.com/guide.html#routing where '/user/:id' ends up as req.params.id. I think it makes sense for the app.resource.path.xxx calls that information in req.params could be passed for some of the information. |
yeah :foo essentially attempts to consume as much as possible within a path segment, whereas * grabs as much as it can spanning segments ("/") |
I've updated my fork to behave as described above: user_path(5) or user_path("5") will result in /users/5. user_path({id: 5}) still works, of course. If there is a collision the object property version will win out. |
Hi guys, I know this is an old thread but I've been working on a router that allows named routes and generating back a URL by route name and parameters. I closely investigated how the express router works especially dispatch area which almost kept the same. If you can have a look at https://github.com/web-napopa/node-reversable-router. I have a single I also have other features in there. Give me shout if you find them useful or not. I got it all working with XRegExp and your |
No description provided.
The text was updated successfully, but these errors were encountered: