pub fn any_service<S, ReqBody, ResBody>(
    svc: S
) -> MethodRouter<ReqBody, S::Error> where
    S: Service<Request<ReqBody>, Response = Response<ResBody>> + Clone + Send + 'static,
    S::Future: Send + 'static,
    ResBody: HttpBody<Data = Bytes> + Send + 'static,
    ResBody::Error: Into<BoxError>, 
Expand description

Route requests to the given service regardless of its method.

Example

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

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

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

Additional methods can still be chained:

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

let service = tower::service_fn(|request: Request<Body>| async {
    // ...
});

let other_service = tower::service_fn(|request: Request<Body>| async {
    // ...
});

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