Module trailing_slash

Source
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
TrailingSlash

Enums§

TrailingSlashAction
TrailingSlashAction

Functions§

add_slash
Create an add slash middleware.
default_add_skipper
Default skipper used for TrailingSlash when it’s action is TrailingSlashAction::Add.
default_remove_skipper
Default skipper used for TrailingSlash when it’s action is TrailingSlashAction::Remove.
remove_slash
Create a remove slash middleware.