Expand description
Generic HTTP client abstraction layer.
This crate provides a unified interface for making HTTP requests across different backend implementations. It defines generic traits for HTTP clients, request builders, and responses, allowing you to write code that works with multiple HTTP client libraries.
§Features
reqwest- Enable the reqwest HTTP client backend (real network requests)simulator- Enable the simulator backend (no-op client for testing)json- Enable JSON serialization/deserialization supportstream- Enable streaming response bodies
§Backends
The crate supports multiple HTTP client backends through feature flags:
- reqwest - Production HTTP client using the
reqwestcrate - simulator - No-op client that returns empty responses, useful for testing
§Examples
Basic usage with the reqwest backend:
use switchy_http::{GenericClient, GenericRequestBuilder, GenericResponse};
let client = switchy_http::Client::new();
let mut response = client.get("https://api.example.com/data").send().await?;
let text = response.text().await?;With JSON support:
use switchy_http::{GenericClient, GenericRequestBuilder};
use serde::Deserialize;
#[derive(Deserialize)]
struct ApiResponse {
message: String,
}
let client = switchy_http::Client::new();
let response = client.get("https://api.example.com/data").send().await?;
let data: ApiResponse = response.json().await?;Re-exports§
pub use switchy_http_models as models;
Modules§
- reqwest
- Reqwest HTTP client backend implementation.
- simulator
- Simulator HTTP client backend implementation.
Structs§
- Client
Builder Wrapper - Wrapper type for generic client builders.
- Client
Wrapper - Wrapper type for generic HTTP clients.
- Request
Builder Wrapper - Wrapper type for generic request builders.
- Response
Wrapper - Wrapper type for generic HTTP responses.
Enums§
Traits§
- Generic
Client - Generic trait for HTTP clients.
- Generic
Client Builder - Generic trait for building HTTP clients.
- Generic
Request Builder - Generic trait for building and configuring HTTP requests.
- Generic
Response - Generic trait for HTTP responses.
Type Aliases§
- Client
- Default HTTP client type alias for the enabled backend.
- Request
Builder - Default request builder type alias for the enabled backend.
- Reqwest
Client - HTTP client type for the reqwest backend.
- Reqwest
Client Builder - Client builder type for the reqwest backend.
- Reqwest
Request Builder - Request builder type for the reqwest backend.
- Reqwest
Response - HTTP response type for the reqwest backend.
- Response
- Default HTTP response type alias for the enabled backend.
- Simulator
Client - HTTP client type for the simulator backend.
- Simulator
Client Builder - Client builder type for the simulator backend.
- Simulator
Request Builder - Request builder type for the simulator backend.
- Simulator
Response - HTTP response type for the simulator backend.