Function axum::routing::get_service
source ·
[−]pub fn get_service<S, ReqBody, ResBody>(
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 GET
requests to the given service.
Example
use axum::{
http::Request,
Router,
routing::get_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 `GET /` will go to `service`.
let app = Router::new().route("/", get_service(service));
Note that get
routes will also be called for HEAD
requests but will have
the response body removed. Make sure to add explicit HEAD
routes
afterwards.