Expand description
§HTTP Client Module
Tanu’s HTTP client provides a high-performance wrapper around hyper with enhanced
logging and testing capabilities. Built directly on hyper for minimal overhead and
precise control over HTTP operations.
§Request/Response Flow (block diagram)
+-------------------+ +-------------------+ +-------------------+
| Client | --> | RequestBuilder | --> | hyper Client |
| get/post/put/... | | headers/body/json | | request(req) |
+-------------------+ +-------------------+ +-------------------+
|
v
+-------------------+ +-------------------+ +-------------------+
| Response | <-- | Log (captured) | <-- | hyper::Response |
| status/headers/ | | request + response| | async response |
| text/json | | timing info | | |
+-------------------+ +-------------------+ +-------------------+
|
v
+-------------------+
| Event channel |
| publish(Http log) |
+-------------------+§Key Features
- High Performance: Built directly on hyper for minimal overhead
- Automatic Logging: Captures all HTTP requests and responses
- Precise Control: Direct access to hyper’s low-level HTTP functionality
- 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)
- Request
Builder - Response
- HTTP response wrapper with enhanced testing capabilities.
- Status
Code - An HTTP status code (
status-codein RFC 9110 et al.). - Version
- Represents a version of the HTTP spec.
Enums§
Traits§
- IntoUrl
- A trait to convert various types into URL strings. This provides API compatibility for URL handling.