axum::routing::method_routing

Function get_service

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

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));

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.