Skip to main content

HttpClient

Trait HttpClient 

Source
pub trait HttpClient:
    Send
    + Sync
    + Clone {
    // Required method
    fn execute<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        request: &'life1 RequestData,
        api_key: &'life2 str,
        timeout_ms: u64,
    ) -> Pin<Box<dyn Future<Output = Result<HttpResponse>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
}
Expand description

Trait for executing HTTP requests.

This abstraction allows for different implementations (production vs. testing) and makes the daemon processing logic testable without making real HTTP calls.

§Example

let client = ReqwestHttpClient::new();
let response = client.execute(&request_data, "api-key", 5000).await?;
println!("Status: {}, Body: {}", response.status, response.body);

Required Methods§

Source

fn execute<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, request: &'life1 RequestData, api_key: &'life2 str, timeout_ms: u64, ) -> Pin<Box<dyn Future<Output = Result<HttpResponse>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Execute an HTTP request.

§Arguments
  • request - The request data containing endpoint, method, path, and body
  • api_key - API key to include in Authorization: Bearer header
  • timeout_ms - Request timeout in milliseconds
§Errors

Returns an error if:

  • The request fails due to network issues
  • The request times out
  • The URL is invalid

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§