goodrouter 1.0.3

a bi directional trie router for all your routing needs
Documentation

GoodRouter, the rust edition

A good router should:

  • work in a server or a client (or any other) environment
  • be able to construct routes based on their name
  • should have a simple API!
  • not do the actual navigation!
  • be framework agnostic
  • be very minimal and simple!

Example

let mut router = Router::new();

router.insert_route("all-products", "/product/all");
router.insert_route("product-detail", "/product/{id}");

// And now we can parse routes!

{
  let route = router.parse_route("/not-found".to_owned(),);
  assert_eq!(route, None);
}

{
  let route = router.parse_route("/product/all".to_owned(),);
  assert_eq!(route, Some(Route{
    name: "all-products".to_owned(),
    parameters: vec![],
  }));
}

{
  let route = router.parse_route("/product/1".to_owned(),);
  assert_eq!(route, Some(Route{
    name: "product-detail".to_owned(),
    parameters: vec![
      ("id", "1"),
    ],
  }));
}

// And we can stringify routes

{
  let path = router.stringify_route(Some(Route{
    name: "all-products".to_owned(),
        parameters: vec![],
  }));
  assert_eq!(path, "/product/all".to_owned(),);
}

{
  let path = router.stringify_route(Some(Route{
    name: "product-detail".to_owned(),
    parameters: vec![
      ("id", "1"),
    ],
  }));
  assert_eq!(path, "/product/2".to_owned());
}