Function any_service

fn any_service<T, S>(svc: T) -> MethodRouter<S, <T as >::Error>
where
    T: Service<axum_core::extract::Request> + Clone + Send + Sync + 'static,
    <T as >::Response: IntoResponse + 'static,
    <T as >::Future: Send + 'static,
    S: Clone

Route requests to the given service regardless of its method.

Example

use axum::{
    extract::Request,
    Router,
    routing::any_service,
    body::Body,
};
use http::Response;
use std::convert::Infallible;

let service = tower::service_fn(|request: Request| async {
    Ok::<_, Infallible>(Response::new(Body::empty()))
});

// All requests to `/` will go to `service`.
let app = Router::new().route("/", any_service(service));
# let _: Router = app;

Additional methods can still be chained:

use axum::{
    extract::Request,
    Router,
    routing::any_service,
    body::Body,
};
use http::Response;
use std::convert::Infallible;

let service = tower::service_fn(|request: Request| async {
    # Ok::<_, Infallible>(Response::new(Body::empty()))
    // ...
});

let other_service = tower::service_fn(|request: Request| async {
    # Ok::<_, Infallible>(Response::new(Body::empty()))
    // ...
});

// `POST /` goes to `other_service`. All other requests go to `service`
let app = Router::new().route("/", any_service(service).post_service(other_service));
# let _: Router = app;