Function axum::routing::method_routing::get_service

source ·
pub fn get_service<T, S, B>(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 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.