From 2f16f7f89915b15de121892eac092c87ed09a46a Mon Sep 17 00:00:00 2001 From: Filip Allberg Date: Fri, 13 Oct 2023 23:05:35 +0200 Subject: [PATCH] Avoid forcing user to have `mut client` --- src/lib.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index de85e22..27698b6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -36,6 +36,20 @@ impl Client { } } + pub fn with_url(ident: IdentificationMethod, url: Url) -> Self { + let timeout = Duration::from_secs(10); + + Self { + ident, + base_url: url, + client: reqwest::ClientBuilder::new() + .timeout(timeout) + .build() + .unwrap(), + timeout, + } + } + /// Set the client's internal base url for all requests. pub fn set_base_url>(&mut self, url: U) -> Result<(), U::Error> { self.base_url = url.try_into()?;