Function axum::service::get[][src]

pub fn get<S, B>(svc: S) -> OnMethod<S, EmptyRouter<S::Error>, B> where
    S: Service<Request<B>> + Clone
Expand description

Route GET requests to the given service.

Example

use axum::{
    http::Request,
    Router,
    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("/", service::get(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.