Crates.io | regex_router |
lib.rs | regex_router |
version | 1.0.2 |
source | src |
created_at | 2021-11-23 15:10:04.509622 |
updated_at | 2021-11-25 19:56:05.136282 |
description | An implementation of request routing via a singular grouped regex (with support for path parameter extraction). |
homepage | https://github.com/Majored/rs-regex-router |
repository | https://github.com/Majored/rs-regex-router |
max_upload_size | |
id | 486277 |
size | 29,267 |
An implementation of request routing via a singular grouped regex (with support for path parameter extraction).
[dependencies]
regex_router = "1.0.2"
An example using a unit handler type:
use regex_router::{RouterBuilder, route};
...
let mut builder = RouterBuilder::<()>::new();
route!(builder; r"/example";; "GET" => ());
route!(builder; r"/test";; "GET" => ());
let router = builder.build().unwrap();
An example declaring path parameters:
let mut builder = RouterBuilder::<()>::new();
route!(builder; r"/example/(\d+)"; "var1"; "GET" => ());
route!(builder; r"/test/(\d+)/(\d+)"; "var1", "var2"; "GET" => ());
let router = builder.build().unwrap();
Dispatching against a router:
match router.dispatch("GET", "/example/500") {
Some(route_match) => {
// Call handler and return response.
}
None => {
// No route match. Return 404.
}
};
An example implementation for hyper
can be found here.
Whether you're wanting to report a bug you've come across during use of this crate or are seeking general help/assistance, please utilise the issues tracker and provide as much detail as possible (eg. recreation steps).
I try to respond to issues within a reasonable timeframe.