-
Notifications
You must be signed in to change notification settings - Fork 74
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
Support regex URL patterns #130
Comments
I'd much rather have the user register custom patterns as a "type" and reference those types by name in the URL pattern instead of using regexes directly. It is implemented like that in Flask: http://flask.pocoo.org/docs/0.11/quickstart/#variable-rules This makes URL patterns easier to read and also allows for parsing in the same step. |
The folks working on |
Any news on that? |
I guess you will have to implement this yourself |
If anyone is interested, I've made the crate rererouter that supports regex captures. extern crate iron;
extern crate regex;
extern crate rererouter;
use regex::Captures;
use iron::prelude::{Iron};
use iron::{status, Request, Response};
use rererouter::RouterBuilder;
fn main() {
let mut router_builder = RouterBuilder::new();
router_builder.get(r"/hello-(?P<name>\w*)", |_: &mut Request, captures: Captures| {
let greeting = format!("Hello, {}!", &captures["name"]);
Ok(Response::with((status::Ok, greeting)))
});
router_builder.get(r"/count-to-(?P<count>\d*)", |_: &mut Request, captures: Captures| {
let count = format!("Let's count to {}!", &captures["count"]);
Ok(Response::with((status::Ok, count)))
});
let router = router_builder.finalize();
Iron::new(router).http("localhost:3000").unwrap();
} |
It'd be great if iron router supported URL patterns as regexes. This way we would be able to declare patterns without any ambiguities and offload some param validation to router (e.g. make sure given ID is 3-digit). Coming from Python community, I am familiar with Django URL dispatch module, which I see as a great fit. Right now router uses router-recognizer module, which, IMHO, is quite complicated compared to plain regexes. I've heard Rust has excellent support for regular expressions, so there is some chance it wouldn't be that hard to write some POC implementation, perhaps with same or even better performance. Any thoughts?
The text was updated successfully, but these errors were encountered: