5 unstable releases

0.3.1 Jun 10, 2024
0.3.0 Jun 7, 2024
0.2.1 Aug 2, 2022
0.2.0 Jun 28, 2022
0.1.0 Jun 21, 2022

#240 in Encoding

Download history 2544/week @ 2024-07-29 2270/week @ 2024-08-05 2020/week @ 2024-08-12 2612/week @ 2024-08-19 2213/week @ 2024-08-26 2535/week @ 2024-09-02 2521/week @ 2024-09-09 2376/week @ 2024-09-16 2409/week @ 2024-09-23 2683/week @ 2024-09-30 2278/week @ 2024-10-07 2532/week @ 2024-10-14 3047/week @ 2024-10-21 2758/week @ 2024-10-28 2524/week @ 2024-11-04 3017/week @ 2024-11-11

11,566 downloads per month
Used in 6 crates (2 directly)

MIT/Apache

34KB
912 lines

Yaup - Yet Another URL Params crate

Serialize your structures as query parameters. I made this crate because I didn't find anything that matched the structure of the query parameters used in Meilisearch.

Specificities of this query parameters format:

  • The crate writes the initial ? if there are parameters to send.
  • You can only serialize structures that follow a "key-value" shape, like structures, HashMap, BTreeMap, etc.
  • Sequences (arrays, vectors, tuples, etc) are comma-separated. { doggo: vec!["kefir", "echo"] } serialize as ?doggo=kefir,echo.
  • Empty and null values are not ignored. { doggo: Vec::new(), catto: None } serialize as ?doggo=&catto=null.
  • Return an error if you try to serialize a structure with multiple levels of key-value structures (i.e., an object containing a HashMap for example).

Example

#[derive(Debug, serde::Serialize)]
enum Filter { New, Registered, Blocked }

#[derive(Debug, serde::Serialize)]
struct Params {
    cursor: Option<usize>,
    per_page: Option<usize>,
    username: String,
    filter: Vec<Filter>,
}

let params = Params {
    cursor: Some(42),
    per_page: None,
    username: String::from("tamo"),
    filter: vec![Filter::New, Filter::Blocked],
};
assert_eq!(
    yaup::to_string(&params).unwrap(),
    "?cursor=42&per_page=null&username=tamo&filter=New,Blocked"
);

Thanks

This was originally a fork of serde_url_params which is still maintained. Thanks, boxdot, for the initial code.

Everything has been rewritten from scratch for the v0.3.0.

License

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this document by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~0.4–1MB
~22K SLoC