Module http

Source
Expand description

§HTTP Client Module

Tanu’s HTTP client provides a wrapper around reqwest::Client with enhanced logging and testing capabilities. It offers the same interface as reqwest::Client while automatically capturing request and response logs for debugging and reporting.

§Key Features

  • Automatic Logging: Captures all HTTP requests and responses
  • Same API as reqwest: Drop-in replacement for familiar reqwest usage
  • Integration with Assertions: Works seamlessly with tanu’s assertion macros
  • Error Handling: Enhanced error types with context for better debugging

§Basic Usage

use tanu::{check_eq, http::Client};

#[tanu::test]
async fn test_api() -> eyre::Result<()> {
    let client = Client::new();
     
    let response = client
        .get("https://api.example.com/users")
        .header("accept", "application/json")
        .send()
        .await?;
     
    check_eq!(200, response.status().as_u16());
     
    let users: serde_json::Value = response.json().await?;
    check!(users.is_array());
     
    Ok(())
}

Modules§

header
HTTP header types

Structs§

Client
Tanu’s HTTP client that provides enhanced testing capabilities.
Log
LogRequest
LogResponse
Method
The Request Method (VERB)
RequestBuilder
Response
HTTP response wrapper with enhanced testing capabilities.
StatusCode
An HTTP status code (status-code in RFC 9110 et al.).
Version
Represents a version of the HTTP spec.

Enums§

Error