Allow duplicate query parameters #2380
-
SummaryHow can I allow a query parameter to occur a second time? I am only interested at the first value, but the second should not result a deserialize error. The following request fails:
#[derive(Deserialize)]
pub struct QueryData {
theme: Theme,
id: u64
} I have also try to use
axum version0.7.1 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
axum uses https://crates.io/crates/serde_urlencoded under the hood so there isn't anything we can do about that. Either open an issue with them or try https://crates.io/crates/serde_qs which also has axum support. Not sure if serde_qs supports it but worth a shot. |
Beta Was this translation helpful? Give feedback.
-
You can use #[derive(Deserialize)]
pub struct QueryData {
#[serde(default)]
theme: Vec<Theme>,
id: u64
} It's also possible to write a custom deserialization function that only extracts the first item from a sequence, but that's not as simple. |
Beta Was this translation helpful? Give feedback.
You can use
axum_extra::extract::Query
(not the same asaxum::extract::Query
) if you change yourQueryData
definition toIt's also possible to write a custom deserialization function that only extracts the first item from a sequence, but that's not as simple.