Module salvo_extra::trailing_slash
source · Available on crate feature
trailing-slash
only.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§
- TrailingSlash
Enums§
- TrailingSlashAction
Functions§
- Create an add slash middleware.
- Default skipper used for
TrailingSlash
when it’s action isTrailingSlashAction::Add
. - Default skipper used for
TrailingSlash
when it’s action isTrailingSlashAction::Remove
. - Create a remove slash middleware.