Skip to main content

picdl_rs/http/
test_client.rs

1use log::debug;
2
3use super::client::{Headers, HttpClient, Query};
4
5/// A test HTTP client. Will just print debug information
6#[derive(Default, Debug, Clone, Copy)]
7pub struct TestClient {}
8
9/// Implements a test HTTP client
10/// Should just log request data at debug level
11impl HttpClient for TestClient {
12    /// Error type for a HTTP client
13    /// Typically should be an enum of client errors
14    ///
15    /// # Example
16    /// ```no_run
17    /// #[derive(Debug)]
18    /// pub enum ReqwestError {
19    ///     Client(reqwest::Error),
20    ///     StatusCode(reqwest::Response),
21    /// }
22    /// ```
23    type Error = String;
24
25    /// GET function that implements a GET request in a specific HTTP client,
26    /// such as reqwest
27    #[inline]
28    async fn get(
29        &self,
30        url: String,
31        headers: &Headers,
32        payload: &Query,
33    ) -> Result<String, Self::Error> {
34        pretty_env_logger::init();
35        debug!("GET request to endpoint {url}");
36        debug!("Headers: {:#?}", headers);
37        debug!("Payload: {:#?}", payload);
38        Err(String::from("Using a test HTTP client"))
39    }
40
41    /// POST function that implements a POST request in a specific HTTP client,
42    /// such as reqwest
43    #[inline]
44    async fn post(
45        &self,
46        url: String,
47        headers: &Headers,
48        payload: &Query,
49    ) -> Result<String, Self::Error> {
50        pretty_env_logger::init();
51        debug!("POST request to endpoint {url}");
52        debug!("Headers: {:#?}", headers);
53        debug!("Payload: {:#?}", payload);
54        Err(String::from("Using a test HTTP client"))
55    }
56}
57