HttpClient

Trait HttpClient 

Source
pub trait HttpClient: Send + Sync {
    // Required methods
    fn post<'life0, 'async_trait>(
        &'life0 self,
        url: String,
        body: Vec<u8>,
        headers: Vec<(String, String)>,
    ) -> Pin<Box<dyn Future<Output = Result<Response, Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn get<'life0, 'async_trait>(
        &'life0 self,
        url: String,
        headers: Vec<(String, String)>,
    ) -> Pin<Box<dyn Future<Output = Result<Response, Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

Define uma interface abstrata para clientes HTTP.

Esta trait permite abstrair operações HTTP comuns, tornando mais fácil mock e testar componentes que fazem requisições HTTP.

Required Methods§

Source

fn post<'life0, 'async_trait>( &'life0 self, url: String, body: Vec<u8>, headers: Vec<(String, String)>, ) -> Pin<Box<dyn Future<Output = Result<Response, Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Executa uma requisição HTTP POST.

§Argumentos
  • url - URL para a requisição
  • body - Corpo da requisição como bytes
  • headers - Cabeçalhos HTTP como pares (nome, valor)
§Retorna
  • Ok(Response) - A resposta HTTP
  • Err(reqwest::Error) - Se ocorrer um erro na requisição
Source

fn get<'life0, 'async_trait>( &'life0 self, url: String, headers: Vec<(String, String)>, ) -> Pin<Box<dyn Future<Output = Result<Response, Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Executa uma requisição HTTP GET.

§Argumentos
  • url - URL para a requisição
  • headers - Cabeçalhos HTTP como pares (nome, valor)
§Retorna
  • Ok(Response) - A resposta HTTP
  • Err(reqwest::Error) - Se ocorrer um erro na requisição

Implementors§

Source§

impl HttpClient for MockHttpClient

Define uma interface abstrata para clientes HTTP.

Esta trait permite abstrair operações HTTP comuns, tornando mais fácil mock e testar componentes que fazem requisições HTTP.

Source§

impl HttpClient for ReqwestClient