Function axum::service::on [−][src]
pub fn on<S, B>(
method: MethodFilter,
svc: S
) -> OnMethod<S, EmptyRouter<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,
handler::on,
service,
Router,
routing::MethodFilter,
};
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));