Get Query 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);
    ()
  });
}


Output



key: alfa, value: bravo
key: charlie, value: delta
        

Note

This uses the url create. It has 104 million downloads and can be installed with cargo add url