Function product_os_router::get_service

source ·
pub fn get_service<T, S>(
    svc: T
) -> MethodRouter<S, <T as Service<Request<Body>>>::Error>
where T: Service<Request<Body>> + Clone + Send + 'static, <T as Service<Request<Body>>>::Response: IntoResponse + 'static, <T as Service<Request<Body>>>::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.