kalgan_router

Crates.iokalgan_router
lib.rskalgan_router
version0.9.1
sourcesrc
created_at2022-02-20 17:09:01.645897
updated_at2022-02-24 14:49:46.110062
descriptionHTTP routing tool based on routes stored in yaml files used by Kalgan Framework.
homepagehttps://kalgan.eduardocasas.com
repositoryhttps://github.com/eduardocasas/kalgan-router
max_upload_size
id535842
size21,303
Eduardo Casas (eduardocasas)

documentation

README

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:

Commit count: 5

cargo fmt