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

query-string-builder

A query string builder for percent encoding key-value pairs

5 releases (3 breaking)

0.4.1 Jul 8, 2023
0.4.0 Jul 8, 2023
0.3.0 Jul 8, 2023
0.2.0 Jul 7, 2023
0.1.0 Jul 7, 2023

#227 in HTTP client

Download history 72/week @ 2024-02-24 5/week @ 2024-03-02 81/week @ 2024-03-30 170/week @ 2024-04-06 138/week @ 2024-04-13

389 downloads per month
Used in waka

EUPL-1.2

11KB
145 lines

A query string builder for percent encoding key-value pairs

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_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&category=fruits%20and%20vegetables?"
    );
}

lib.rs:

A query string builder for percent encoding key-value pairs

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;

let qs = QueryString::new()
            .with_value("q", "🍎 apple")
            .with_opt_value("color", None::<String>)
            .with_opt_value("category", Some("fruits and vegetables?"));

assert_eq!(
    format!("example.com/{qs}"),
    "example.com/?q=%F0%9F%8D%8E%20apple&category=fruits%20and%20vegetables?"
);

Dependencies

~14KB