2 releases
0.9.1 | Feb 24, 2022 |
---|---|
0.9.0 | Feb 20, 2022 |
#1164 in HTTP server
Used in kalgan
20KB
337 lines
kalgan-router
HTTP routing tool based on routes stored in yaml files used by Kalgan Framework.
Examples
This is the yaml file to be used in the following tests:
## tests/routes.yaml
routes:
- home:
path: /
controller: home_controller::index
methods: get
- user:
path: /user/{id}
controller: user_controller::crud
middleware: user_middleware::test
methods: get, post, delete, put
requirements:
id: "^[0-9]+"
use kalgan_router::Router;
let router = Router::new("tests/routes.yaml");
assert_eq!(router.get_uri("home", HashMap::new()), "/".to_string())
let mut parameters = HashMap::new();
parameters.insert("id", "101".to_string());
assert_eq!(router.get_uri("user", parameters), "/user/101".to_string())
let route = router.get_route("/", "get").unwrap();
assert_eq!(route.get_name(), &"home".to_string());
assert_eq!(route.get_path(), &"/".to_string());
assert_eq!(route.get_methods(), &vec!["get".to_string()]);
assert_eq!(route.get_controller(), &"home_controller::index".to_string());
assert_eq!(route.get_middleware(), &"".to_string());
Documentation
For further information please visit:
License
This crate is licensed under either of the following licenses:
Dependencies
~4–6MB
~109K SLoC