Open ghost opened 1 year ago
little bit more information:
If you run an axum server with following code:
use axum::{body::Body, http::Request, routing, Router}; async fn get(req: Request<Body>) { println!("{}", req.uri()); } #[tokio::main] async fn main() { let api = Router::new().route("/health", routing::get(get)); let router = Router::new().nest("/api", api); axum::Server::bind(&"0.0.0.0:3030".parse().unwrap()) .serve(router.into_make_service()) .await .unwrap(); }
and request to localhost:3030/api/health?foo=bar, output is like:
localhost:3030/api/health?foo=bar
/health?foo=bar
When we use nested router, axum's req.uri only shows matched path of the nested router.
req.uri
We can use MatchedPath to retrieve full path, but we have to somehow concatenate the query string.
little bit more information:
If you run an axum server with following code:
and request to
localhost:3030/api/health?foo=bar
, output is like:When we use nested router, axum's
req.uri
only shows matched path of the nested router.