rocket_router
Dynamic routing system for Rocket
Caveats
- Each file should export only one route, named the same as the file itself.
- After adding a new route, save (or
touch
)main.rs
to see the changes.
Usage
Cargo.toml
[dependencies]
rocket_router = { git = "https://github.com/DavidArsene/rocket_router" }
main.rs
#[macro_use] extern crate rocket;
use rocket_router::router;
#[router]
#[launch]
async fn rocket() -> _ {
rocket::build().router()
}
routes/hello/world.rs
#[get("/<name>/<age>")]
pub fn world(name: &str, age: u8) -> String {
format!("Hello, {} year old named {}!", age, name)
}
Specifying a custom route folder:
#[macro_use] extern crate rocket;
use rocket_router::router;
#[router("custom")]
#[launch]
async fn rocket() -> _ {
rocket::build().router()
}
License
rocket_router
is licensed under either of the following, at your option: