diff --git a/src/util/request.rs b/src/util/request.rs index 16f4d4f..ad1352d 100644 --- a/src/util/request.rs +++ b/src/util/request.rs @@ -1,6 +1,8 @@ use reqwest::StatusCode; +use std::time::Duration; pub struct Request<'a> { + pub client: reqwest::Client, pub base_url: &'a str, pub full_url: Option<&'a str>, } @@ -8,6 +10,11 @@ pub struct Request<'a> { impl<'a> Request<'a> { pub fn new() -> Self { Request { + client: reqwest::ClientBuilder::new() + .use_rustls_tls() + .timeout(Duration::from_secs(30)) + .build() + .unwrap(), base_url: "https://site.api.espn.com/apis/site/v2/sports/football", full_url: None, } @@ -26,7 +33,7 @@ impl<'a> Request<'a> { T: for<'de> serde::Deserialize<'de>, { println!("{}", url); - let api_result = match reqwest::get(url).await { + let api_result = match self.client.get(url).send().await { Ok(r) => r, Err(e) => return Err(Box::new(e)), };