Routing based on presence of query parameters #2043
Answered
by
davidpdrsn
davidv1992
asked this question in
Q&A
-
I am building a webserver that needs to handle get requests to the same path very differently based on whether certain query parameters are present or not. Is it possible to do route these differently in axum, and if so, how? |
Beta Was this translation helpful? Give feedback.
Answered by
davidpdrsn
Jun 14, 2023
Replies: 1 comment 3 replies
-
Extract Query<HashMap<String, String>>. Then you check which keys are there. You can probably also use a struct with Option and #[serde(default)] |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yep you need to handle it yourself in the handle functions. Axum’s router doesn’t know about query params.