mirror of
https://github.com/tokio-rs/axum.git
synced 2026-08-28 00:00:20 +02:00
Clarify required response body type when routing to tower::Services (#69)
This commit is contained in:
+13
@@ -487,11 +487,24 @@
|
||||
//! let app = route(
|
||||
//! // Any request to `/` goes to a service
|
||||
//! "/",
|
||||
//! // Services who's response body is not `axum::body::BoxBody`
|
||||
//! // can be wrapped in `axum::service::any` (or one of the other routing filters)
|
||||
//! // to have the response body mapped
|
||||
//! service::any(service_fn(|_: Request<Body>| async {
|
||||
//! let res = Response::new(Body::from("Hi from `GET /`"));
|
||||
//! Ok(res)
|
||||
//! }))
|
||||
//! ).route(
|
||||
//! "/foo",
|
||||
//! // This service's response body is `axum::body::BoxBody` so
|
||||
//! // it can be routed to directly.
|
||||
//! service_fn(|req: Request<Body>| async move {
|
||||
//! let body = Body::from(format!("Hi from `{} /foo`", req.method()));
|
||||
//! let body = axum::body::box_body(body);
|
||||
//! let res = Response::new(body);
|
||||
//! Ok(res)
|
||||
//! })
|
||||
//! ).route(
|
||||
//! // GET `/static/Cargo.toml` goes to a service from tower-http
|
||||
//! "/static/Cargo.toml",
|
||||
//! service::get(ServeFile::new("Cargo.toml"))
|
||||
|
||||
Reference in New Issue
Block a user