Function axum::routing::on_service
source ·
[−]pub fn on_service<S, ReqBody, ResBody>(
filter: MethodFilter,
svc: S
) -> MethodRouter<ReqBody, S::Error> where
S: Service<Request<ReqBody>, Response = Response<ResBody>> + Clone + Send + 'static,
S::Future: Send + 'static,
ResBody: HttpBody<Data = Bytes> + Send + 'static,
ResBody::Error: Into<BoxError>,
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));