HttpClient

Trait HttpClient 

Source
pub trait HttpClient: Send + Sync {
    // Required method
    fn execute<'life0, 'async_trait>(
        &'life0 self,
        request: Request<Vec<u8>>,
    ) -> Pin<Box<dyn Future<Output = Result<Response<Vec<u8>>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

定义 HTTP 客户端行为的 Trait。

可根据爱好替换底层的 HTTP 实现。

Required Methods§

Source

fn execute<'life0, 'async_trait>( &'life0 self, request: Request<Vec<u8>>, ) -> Pin<Box<dyn Future<Output = Result<Response<Vec<u8>>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

执行一个 HTTP 请求并返回响应。

§参数
  • request: 要执行的 HTTP 请求。
§返回

包含 HTTP 响应的 Result。

Implementors§

Source§

impl HttpClient for ReqwestHttpClient

基于 reqwest 库的默认 HTTP 客户端实现。