Function axum::routing::method_routing::on_service
source · pub fn on_service<T, S>(
filter: MethodFilter,
svc: T,
) -> MethodRouter<S, T::Error>
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));