gotham
gotham copied to clipboard
Bi-directional routing
Especially with the idea of providing for modular web apps, it would be incredibly useful to be able to do something like
Response::new()
.with_header(Location::new(url_for(other_handler))
(this is intended to echo a Rails feature). In other words: Gotham routing already accomplishes routing from a URL to a handler. What this issue proposes is being able to go from a handler and produce URL(s). (Plural because: relative, same base URL as the request, a canonical base...)
There's a number of ways to accomplish this, but one requirement (which isn't addressed by e.g. strings as url paths) is that routing within a module of handlers still work if they're put within a routing tree (or moved around in the tree.)
A further feature requirement would be the ability to "link up" modules - authentication tools often need to know about where to redirect once a user is authenticated, for instance, and reusability relies on being able to configure this into the modules when they're routed.
Potentially related to #7. If we could find a way to map handlers back to URLs, that would solve (most of) the "named routes" problem without needing to explicitly name any routes.
I totally missed #7. From experience implementing this kind of thing, the routes do need some fully-qualified identifier - names are the most obvious solution. If they associate to a handler, and handlers can reference each other (even across modules) that would be a really elegant solution.
What you effectively want to do is say "I want a link that will result in HandlerFoo being called with parameters
Handlers as names (or even routing nodes as names - since method/content-type/... is outside the URI scope) is a good idea though.