Function get_service

fn get_service<T, S>(svc: T) -> MethodRouter<S, <T as >::Error>
where
    T: Service<Request> + Clone + Send + Sync + 'static,
    <T as >::Response: IntoResponse + 'static,
    <T as >::Future: Send + 'static,
    S: Clone

Route GET requests to the given service.

Example

use axum::{
    extract::Request,
    Router,
    routing::get_service,
    body::Body,
};
use http::Response;
use std::convert::Infallible;

let service = tower::service_fn(|request: Request| async {
    Ok::<_, Infallible>(Response::new(Body::empty()))
});

// Requests to `GET /` will go to `service`.
let app = Router::new().route("/", get_service(service));
# let _: Router = app;

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.