Expand description
Trailing slash middleware.
§Examples
- Add trailing slash:
use salvo_core::prelude::*;
use salvo_extra::trailing_slash::add_slash;
#[handler]
async fn hello() -> &'static str {
"Hello"
}
#[tokio::main]
async fn main() {
let router = Router::with_hoop(add_slash())
.push(Router::with_path("hello").get(hello))
.push(Router::with_path("hello.world").get(hello));
let acceptor = TcpListener::new("0.0.0.0:5800").bind().await;
Server::new(acceptor).serve(router).await;
}
- Remove trailing slash:
use salvo_core::prelude::*;
use salvo_extra::trailing_slash::remove_slash;
#[handler]
async fn hello() -> &'static str {
"Hello"
}
#[tokio::main]
async fn main() {
let router = Router::with_hoop(remove_slash().redirect_code(StatusCode::TEMPORARY_REDIRECT))
.push(Router::with_path("hello").get(hello))
.push(Router::with_path("hello.world").get(hello));
let acceptor = TcpListener::new("0.0.0.0:5800").bind().await;
Server::new(acceptor).serve(router).await;
}
Structs§
- Trailing
Slash - TrailingSlash
Enums§
- Trailing
Slash Action - TrailingSlashAction
Functions§
- add_
slash - Create an add slash middleware.
- default_
add_ skipper - Default skipper used for
TrailingSlash
when it’s action isTrailingSlashAction::Add
. - default_
remove_ skipper - Default skipper used for
TrailingSlash
when it’s action isTrailingSlashAction::Remove
. - remove_
slash - Create a remove slash middleware.