Skip to content

How to get an array of key-value pairs in a query #1482

Answered by jplatte
tingfeng-key asked this question in Q&A
Discussion options

You must be logged in to vote

OP will have to use serde_qs, serde_html_form which the axum-extra extractor is based on doesn't really allow this syntax, unless you want a flat list of fields in which case serde(rename) works with axums Query extractor as well:

#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
struct QueryParameters {
    page_num: u32,
    page_size: u32,
    dict_name: u32,
    dict_type: u32,
    #[serde(rename = "params[beginTime]")]
    begin_time: String,
    #[serde(rename = "params[endTime]")]
    end_time: String,
}

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@jplatte
Comment options

Answer selected by yanns
@tingfeng-key
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants