I'm trying to insert some required params
to a call to a particular API, but the params
are not being appropriately incorporated into the URL.
This works:
fn main() -> Result<(), Box<dyn std::error::Error>> {
let url_full = "https://holidayapi.com/v1/holidays?key=<my-api-key>&country=US&year=2020";
let client = reqwest::blocking::Client::new();
let res = client.get(url_full).send()?;
println!("holidays = {:#?}", res.text().unwrap());
Ok(())
}
This does not work:
fn main() -> Result<(), Box<dyn std::error::Error>> {
let url = "https://holidayapi.com/v1/holidays";
let api_key = "<my-api-key>";
let params = [
("key", api_key),
("country", "US"),
("year", "2020")
];
let client = reqwest::blocking::Client::new();
let res = client.get(url)
.form(¶ms)
.send()?;
println!("holidays = {:#?}", res.text().unwrap());
Ok(())
}
The server responds with a 401 error stating that an API key parameter is required. I cannot find the link now, but I know there is an example that shows this format somewhere in the reqwest
docs.