melvin_ob/http_handler/
http_client.rs

1/// A simple wrapper around `reqwest::Client` used to manage HTTP requests
2/// with a preconfigured base URL and default settings.
3///
4/// This client is used for making REST API calls to the DRS backend.
5/// It sets a fixed timeout and allows easy reuse of the HTTP client infrastructure.
6#[derive(Debug)]
7pub(crate) struct HTTPClient {
8    /// The underlying `reqwest::Client` used to perform HTTP requests.
9    client: reqwest::Client,
10    /// Base URL for the API, prepended to all endpoint paths. 
11    base_url: String,
12}
13
14impl HTTPClient {
15    /// Constructs a new `HTTPClient` with the given base URL.
16    ///
17    /// This client has a default request timeout of 5 seconds.
18    ///
19    /// # Arguments
20    /// * `base_url` – The root URL for all HTTP requests (e.g., `"http://localhost:8000/api"`).
21    ///
22    /// # Returns
23    /// A configured `HTTPClient` instance.
24    pub(crate) fn new(base_url: &str) -> HTTPClient {
25        HTTPClient {
26            client: reqwest::Client::builder()
27                //.danger_accept_invalid_certs(true)
28                .timeout(std::time::Duration::from_secs(5))
29                .build()
30                .unwrap(),
31            base_url: String::from(base_url),
32        }
33    }
34
35    /// Returns a reference to the internal `reqwest::Client`.
36    pub(super) fn client(&self) -> &reqwest::Client { &self.client }
37    /// Returns the base URL that the client was initialized with.
38    pub(crate) fn url(&self) -> &str { self.base_url.as_str() }
39}