#query-string #url #query-argument

query-string-builder

A query string builder for percent encoding key-value pairs

9 releases (5 breaking)

0.6.0 Jun 7, 2024
0.5.1 May 24, 2024
0.4.2 May 23, 2024
0.4.1 Jul 8, 2023
0.1.0 Jul 7, 2023

#621 in HTTP client

Download history 65/week @ 2025-10-23 100/week @ 2025-10-30 98/week @ 2025-11-06 81/week @ 2025-11-13 32/week @ 2025-11-20 69/week @ 2025-11-27 1/week @ 2025-12-11 22/week @ 2025-12-18 61/week @ 2026-01-22 93/week @ 2026-01-29 46/week @ 2026-02-05

200 downloads per month
Used in 2 crates

EUPL-1.2

28KB
582 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

~17KB