Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Path extractor documentation does not mention that multiple Path arguments should not be used #2313

Closed
1 task done
uckelman opened this issue Nov 13, 2023 · 0 comments · Fixed by #2314
Closed
1 task done

Comments

@uckelman
Copy link
Contributor

  • I have looked for existing issues (including closed) about this

Bug Report

Version

├── axum v0.6.20
│   ├── axum-core v0.3.4
│   ├── axum-macros v0.3.8 (proc-macro)

Platform

Linux scylla 6.5.10-200.fc38.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Nov  2 19:59:55 UTC 2023 x86_64 GNU/Linux

Description

A few days ago on Discord somebody posted code like the following, wondering why it doesn't work:

async fn handler(
    Path(package): Path<String>,
    Path(path): Path<String>,
) -> Result<(), AppError> {
    ....
}

 let app = axum::Router::new()
        .route("/:package/v1/*path", get(handler));

It's natural to see the Path extractor and think that you need one as an argument in your handler for each path component you want to capture. When I saw this, I knew exactly what the problem was, because I had exactly the same problem a few weeks ago.

While the documentation for Path does say that it extracts multiple components to tuples, it never says explicitly that you should not try to extract multiple components each with its own Path extractor like above. Saying this explicitly would head off a common confusion for new users.

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 a pull request may close this issue.

1 participant