pub fn on_service<T, S>(
    filter: MethodFilter,
    svc: T
) -> MethodRouter<S, <T as Service<Request<Body>>>::Error>
where T: Service<Request<Body>> + Clone + Send + 'static, <T as Service<Request<Body>>>::Response: IntoResponse + 'static, <T as Service<Request<Body>>>::Future: Send + 'static, S: Clone,
Expand description

Route requests with the given method to the service.

§Example

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

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

// Requests to `POST /` will go to `service`.
let app = Router::new().route("/", on_service(MethodFilter::POST, service));