normal_reqwest/
normal_reqwest.rs

1use eskom_se_push_api::{
2  allowance::{AllowanceCheck, AllowanceCheckURLBuilder},
3  constants::TOKEN_KEY,
4  reqwest_blocking_client::handle_reqwest_response_blocking,
5  Endpoint,
6};
7use http::header;
8
9fn main() {
10  let api = AllowanceCheckURLBuilder::default().build().unwrap();
11  // Need to import the Endpoint trait
12  let mut headers = header::HeaderMap::new();
13  headers.insert(
14    TOKEN_KEY,
15    header::HeaderValue::from_str("XXXXXXXXXXXXXXXXXXXXXXX").unwrap(),
16  );
17  let client = reqwest::blocking::ClientBuilder::new()
18    .default_headers(headers)
19    .build()
20    .unwrap();
21  let response = client.get(api.url().unwrap().as_str()).send();
22  match handle_reqwest_response_blocking::<AllowanceCheck>(response) {
23    Ok(allowance) => {
24      println!(
25        "You have made {} API calls today",
26        allowance.allowance.count
27      );
28    }
29    Err(e) => {
30      eprintln!("Error: {}", e);
31    }
32  }
33}