Skip to content

docs: fix route_service example for Body API - #3890

Merged
mladedav merged 3 commits into
tokio-rs:mainfrom
akasakariko:docs/fix-route-service-boxbody
Sep 14, 2026
Merged

mladedav merged 3 commits into
tokio-rs:mainfrom
akasakariko:docs/fix-route-service-boxbody

Conversation

@akasakariko

@akasakariko akasakariko commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

The Router::route_service example still refers to axum::body::BoxBody, removed in 0.7.

Solution

  • Describe the request body and IntoResponse requirements.
  • Replace outdated example comments and remove unused imports.
  • Link to any_service and get_service for use with Router::route.
  • Keep the example as an executable doctest. Removed the additional routing tests following review; this is a documentation-only change.

Fixes #2536

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
Comment thread axum/src/docs/routing/route_service.md Outdated
Comment on lines +13 to +14
without a `Router`. You do **not** need them to map response bodies — any
[`IntoResponse`] type works with `route_service` directly.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't mention what people don't need to do, just that they need to return a IntoResponse.

Comment thread axum/src/docs/routing/route_service.md Outdated
// 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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no point in explicitly mentioning that boxing isn't required.

Comment thread axum/src/docs/routing/route_service.md Outdated
return a response that implements [`IntoResponse`]. The error type must be
[`Infallible`].

[`any_service`], [`get_service`], and the other `*_service` filters turn a

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this section is relevant enough, maybe just link to those docs if you think it could help someone.

Comment thread axum/src/routing/tests/route_service.rs Outdated
@@ -0,0 +1,210 @@
//! Regression tests for https://github.com/tokio-rs/axum/issues/2536

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@akasakariko

Copy link
Copy Markdown
Contributor Author

Thanks @mladedav — addressed in 7d471fa.

Removed both statements about boxing not being required, shortened the method-router discussion to links to any_service and get_service, and removed the additional routing test module rather than duplicating existing coverage. The example remains an executable doctest. The final diff only changes the documentation and changelog; no runtime code or public API changes.

Local verification:

  • cargo test --locked -p axum --all-features --doc route_service: 2 passed.
  • cargo test --locked -p axum --all-features: 383 unit tests, 1 integration test, and 178 doctests passed; 1 existing doctest ignored.
  • cargo fmt --all --check: passed.
  • cargo +beta clippy --locked -p axum --all-targets --all-features -- -D warnings: passed.
  • RUSTDOCFLAGS="-D rustdoc::all -A rustdoc::private-doc-tests" cargo doc --locked -p axum --all-features --no-deps: passed.

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.

@mladedav mladedav left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@mladedav
mladedav merged commit 0b9325b into tokio-rs:main Sep 14, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Router::route_service() example code is out of date

2 participants