Function on_service

fn on_service<T, S>(filter: crate::routing::MethodFilter, 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 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));
# let _: Router = app;