Function axum::routing::method_routing::on_service
source · [−]pub fn on_service<T, S, B>(
filter: MethodFilter,
svc: T
) -> MethodRouter<S, B, T::Error>where
T: Service<Request<B>> + Clone + Send + 'static,
T::Response: IntoResponse + 'static,
T::Future: Send + 'static,
B: HttpBody + Send + 'static,
S: Clone,
Expand description
Route requests with the given method to the service.
Example
use axum::{
http::Request,
routing::on,
Router,
routing::{MethodFilter, on_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("/", on_service(MethodFilter::POST, service));