Repository navigation
docs: fix route_service example for Body API - #3890
Conversation
The example still referred to axum::body::BoxBody, which was removed in 0.7. Clarify when any_service is useful versus route_service, and add regression tests for the documented routing behavior. Fixes: tokio-rs#2536
| without a `Router`. You do **not** need them to map response bodies — any | ||
| [`IntoResponse`] type works with `route_service` directly. |
There was a problem hiding this comment.
Don't mention what people don't need to do, just that they need to return a IntoResponse.
| // This service's response body is `axum::body::BoxBody` so | ||
| // it can be routed to directly. | ||
| // `route_service` takes any `Service<Request>` whose response | ||
| // implements `IntoResponse`. No body boxing is required. |
There was a problem hiding this comment.
There's no point in explicitly mentioning that boxing isn't required.
| return a response that implements [`IntoResponse`]. The error type must be | ||
| [`Infallible`]. | ||
|
|
||
| [`any_service`], [`get_service`], and the other `*_service` filters turn a |
There was a problem hiding this comment.
I don't think this section is relevant enough, maybe just link to those docs if you think it could help someone.
| @@ -0,0 +1,210 @@ | |||
| //! Regression tests for https://github.com/tokio-rs/axum/issues/2536 | |||
There was a problem hiding this comment.
I don't think we need "regression tests" for a documentation issue.
I mean some of the tests may be useful, but then some of them really don't test anything other tests in the same file already do and I suspect there is also overlap with standard route/route_service/any_service tests.
If you think these tests are worthwhile, please put them next to where the method they're testing is already being tested.
|
Thanks @mladedav — addressed in 7d471fa. Removed both statements about boxing not being required, shortened the method-router discussion to links to Local verification:
GitHub CI for this revision: all 17 checks passed, including MSRV, stable/beta tests, cargo-hack and cross-target checks (run 34731133219). Updated the PR description to reflect the reduced scope. |
Motivation
The
Router::route_serviceexample still refers toaxum::body::BoxBody, removed in 0.7.Solution
IntoResponserequirements.any_serviceandget_servicefor use withRouter::route.Fixes #2536