Function axum::routing::service_method_routing::on [−][src]
pub fn on<S, B>(
method: MethodFilter,
svc: S
) -> MethodRouter<S, MethodNotAllowed<S::Error>, B> where
S: Service<Request<B>> + Clone,
Expand description
Route requests with the given method to the service.
Example
use axum::{
http::Request,
routing::on,
Router,
routing::{MethodFilter, service_method_routing as 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()))
});
// Requests to `POST /` will go to `service`.
let app = Router::new().route("/", service::on(MethodFilter::POST, service));