Function axum::routing::method_routing::any

source ·
pub fn any<H, T, S, B>(handler: H) -> MethodRouter<S, B, Infallible>where
    H: Handler<T, S, B>,
    B: HttpBody + Send + 'static,
    T: 'static,
    S: Clone + Send + Sync + 'static,
Expand description

Route requests with the given handler regardless of the method.

Example

use axum::{
    routing::any,
    Router,
};

async fn handler() {}

// All requests to `/` will go to `handler`.
let app = Router::new().route("/", any(handler));

Additional methods can still be chained:

use axum::{
    routing::any,
    Router,
};

async fn handler() {}

async fn other_handler() {}

// `POST /` goes to `other_handler`. All other requests go to `handler`
let app = Router::new().route("/", any(handler).post(other_handler));