Crate pathrouter

source ·
Expand description

Recognizes URL path patterns with support for dynamic and wildcard segments

Examples

use pathrouter::{Router, Params};

let mut router = Router::new();

router.add("/posts", "posts");
router.add("/posts/:post_id", "post");

let (endpoint, params) = router.route("/posts/1").unwrap();

assert_eq!(*endpoint, "post");
let mut path_params = Params::new();
path_params.insert("post_id", "1");
assert_eq!(params, path_params);

Routing params

The router supports four kinds of route segments:

  • segments: these are of the format /a/b.
  • params: these are of the format /a/:b.
  • wildcards: these are of the format /a/*b.

Structs