home ~ projects ~ socials

Get Querystring Params From A URL In Rust

This is what I'm doing to get query params in Rust:

use url::Url;

fn main() {
    let url = Url::parse("https://www.example.com/index.html?alfa=bravo&charlie=delta")
        .expect("Could not parse url");
    let query_pairs = url.query_pairs();
    query_pairs.for_each(|param| {
        println!("key: {}, value: {}", param.0, param.1);
        ()
    });
}

This uses the url create (which has 104 million downloads)

-- end of line --