pub async fn send(&self, request: HttpRequestBuilder) -> crate::Result<Response> {
    let method = Method::from_bytes(request.method.to_uppercase().as_bytes())?;
    let mut request_builder = self.0.request(method, &request.url);

    if let Some(query) = request.query {
      request_builder = request_builder.query(&query);
    }

    if let Some(headers) = request.headers {
      for (header, header_value) in headers.iter() {
        request_builder =
          request_builder.header(HeaderName::from_bytes(header.as_bytes())?, header_value);
      }
    }

    if let Some(timeout) = request.timeout {
      request_builder = request_builder.timeout(Duration::from_secs(timeout));
    }

    let response = if let Some(body) = request.body {
      match body {
        Body::Bytes(data) => request_builder.body(Bytes::from(data)).send().await?,
        Body::Text(text) => request_builder.body(Bytes::from(text)).send().await?,
        Body::Json(json) => request_builder.json(&json).send().await?,
        Body::Form(form_body) => {
          let mut form = Vec::new();
          for (name, part) in form_body.0 {
            match part {
              FormPart::Bytes(bytes) => form.push((name, serde_json::to_string(&bytes)?)),
              FormPart::File(file_path) => form.push((name, serde_json::to_string(&file_path)?)),
              FormPart::Text(text) => form.push((name, text)),
            }
          }
          request_builder.form(&form).send().await?
        }
      }
    } else {
      request_builder.send().await?
    };

    let response = response.error_for_status()?;
    Ok(Response(
      request.response_type.unwrap_or(ResponseType::Json),
      response,
    ))
  }
/// Executes an HTTP request
///
/// The response will be transformed to String,
/// If reading the response as binary, the byte array will be serialized using serde_json
Executes an HTTP request
The response will be transformed to String,
If reading the response as binary, the byte array will be serialized using serde_json
Executes an HTTP request The response will be transformed to String If reading the response as binary the byte array will be serialized using serde_json
pub async fn send(&self, request: HttpRequestBuilder) -> crate::Result<Response> {
    let method = Method::from_bytes(request.method.to_uppercase().as_bytes())?;
    let mut request_builder = self.0.request(method, &request.url);
    if let Some(query) = request.query {
      request_builder = request_builder.query(&query);
    }
    if let Some(headers) = request.headers {
      for (header, header_value) in headers.iter() {
        request_builder =
          request_builder.header(HeaderName::from_bytes(header.as_bytes())?, header_value);
      }
    }
    if let Some(timeout) = request.timeout {
      request_builder = request_builder.timeout(Duration::from_secs(timeout));
    }
    let response = if let Some(body) = request.body {
      match body {
        Body::Bytes(data) => request_builder.body(Bytes::from(data)).send().await?,
        Body::Text(text) => request_builder.body(Bytes::from(text)).send().await?,
        Body::Json(json) => request_builder.json(&json).send().await?,
        Body::Form(form_body) => {
          let mut form = Vec::new();
          for (name, part) in form_body.0 {
            match part {
              FormPart::Bytes(bytes) => form.push((name, serde_json::to_string(&bytes)?)),
              FormPart::File(file_path) => form.push((name, serde_json::to_string(&file_path)?)),
              FormPart::Text(text) => form.push((name, text)),
            }
          }
          request_builder.form(&form).send().await?
        }
      }
    } else {
      request_builder.send().await?
    };
    let response = response.error_for_status()?;
    Ok(Response(
      request.response_type.unwrap_or(ResponseType::Json),
      response,
    ))
  }
pub async fn send ( & self , request : HttpRequestBuilder ) -> crate :: Result < Response > { let method = Method :: from_bytes ( request . method . to_uppercase ( ) . as_bytes ( ) ) ? ; let mut request_builder = self . 0 . request ( method , & request . url ) ; if let Some ( query ) = request . query { request_builder = request_builder . query ( & query ) ; } if let Some ( headers ) = request . headers { for ( header , header_value ) in headers . iter ( ) { request_builder = request_builder . header ( HeaderName :: from_bytes ( header . as_bytes ( ) ) ? , header_value ) ; } } if let Some ( timeout ) = request . timeout { request_builder = request_builder . timeout ( Duration :: from_secs ( timeout ) ) ; } let response = if let Some ( body ) = request . body { match body { Body :: Bytes ( data ) => request_builder . body ( Bytes :: from ( data ) ) . send ( ) . await ? , Body :: Text ( text ) => request_builder . body ( Bytes :: from ( text ) ) . send ( ) . await ? , Body :: Json ( json ) => request_builder . json ( & json ) . send ( ) . await ? , Body :: Form ( form_body ) => { let mut form = Vec :: new ( ) ; for ( name , part ) in form_body . 0 { match part { FormPart :: Bytes ( bytes ) => form . push ( ( name , serde_json :: to_string ( & bytes ) ? ) ) , FormPart :: File ( file_path ) => form . push ( ( name , serde_json :: to_string ( & file_path ) ? ) ) , FormPart :: Text ( text ) => form . push ( ( name , text ) ) , } } request_builder . form ( & form ) . send ( ) . await ? } } } else { request_builder . send ( ) . await ? } ; let response = response . error_for_status ( ) ? ; Ok ( Response ( request . response_type . unwrap_or ( ResponseType :: Json ) , response , ) ) }
Executes an HTTP request
The response will be transformed to String,
If reading the response as binary, the byte array will be serialized using serde_json
Executes an HTTP request The response will be transformed to String If reading the response as binary the byte array will be serialized using serde_json
&self
request
HttpRequestBuilder
&self
request
HttpRequestBuilder