#query-string #url #urlencode #query-argument

query-string-builder

A query string builder for percent encoding key-value pairs

8 releases (4 breaking)

new 0.5.1 May 24, 2024
0.5.0 May 24, 2024
0.4.2 May 23, 2024
0.4.1 Jul 8, 2023
0.1.0 Jul 7, 2023

#155 in HTTP client

Download history 60/week @ 2024-02-22 17/week @ 2024-02-29 19/week @ 2024-03-28 131/week @ 2024-04-04 180/week @ 2024-04-11 96/week @ 2024-04-18 99/week @ 2024-04-25 286/week @ 2024-05-02 25/week @ 2024-05-09 44/week @ 2024-05-16

472 downloads per month
Used in waka

EUPL-1.2

15KB
230 lines

A query string builder for percent encoding key-value pairs

Crates.io Crates.io codecov

This is a tiny helper crate for simplifying the construction of URL query strings. The initial ? question mark is automatically prepended.

Example

use query_string_builder::QueryString;

fn main() {
    let qs = QueryString::new()
        .with_value("q", "apple")
        .with_value("tasty", true)
        .with_value("weight", 70.0)
        .with_opt_value("color", None::<String>)
        .with_opt_value("category", Some("fruits and vegetables?"));

    assert_eq!(
        format!("https://example.com/{qs}"),
        "https://example.com/?q=apple&tasty=true&weight=70.0&category=fruits%20and%20vegetables?&tasty=true"
    );
}

Dependencies

~14KB