Invalid URL param. wrong number of parameters: 2 expected 1 #328
Answered
by
jplatte
shengsheng
asked this question in
Q&A
-
How to get multi path params in handler function? use axum::{Router, extract::Path, handler::get, response::Html};
use std::net::SocketAddr;
#[tokio::main]
async fn main() {
// build our application with a route
let app = Router::new().route("/:type/:id", get(handler));
// run it
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
println!("listening on {}", addr);
axum::Server::bind(&addr)
.serve(app.into_make_service())
.await
.unwrap();
}
async fn handler(Path(ty): Path<String>, Path(id): Path<u8>) -> Html<String> {
let content = format!("<p>{}</p><p>{}</p>", ty, id);
Html(content)
}
|
Beta Was this translation helpful? Give feedback.
Answered by
jplatte
Sep 17, 2021
Replies: 1 comment 2 replies
-
What you need is one I wonder whether it would be feasible to make what you wrote work though 🤔 |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
davidpdrsn
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What you need is one
Path<(String, u8)>
extractor rather than two separate ones.I wonder whether it would be feasible to make what you wrote work though 🤔