Skip to main content

Crate switchy_http

Crate switchy_http 

Source
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 support
  • stream - Enable streaming response bodies

§Backends

The crate supports multiple HTTP client backends through feature flags:

  • reqwest - Production HTTP client using the reqwest crate
  • 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§

ClientBuilderWrapper
Wrapper type for generic client builders.
ClientWrapper
Wrapper type for generic HTTP clients.
RequestBuilderWrapper
Wrapper type for generic request builders.
ResponseWrapper
Wrapper type for generic HTTP responses.

Enums§

Error
Errors that can occur when making HTTP requests.
Header
Common HTTP header names.

Traits§

GenericClient
Generic trait for HTTP clients.
GenericClientBuilder
Generic trait for building HTTP clients.
GenericRequestBuilder
Generic trait for building and configuring HTTP requests.
GenericResponse
Generic trait for HTTP responses.

Type Aliases§

Client
Default HTTP client type alias for the enabled backend.
RequestBuilder
Default request builder type alias for the enabled backend.
ReqwestClient
HTTP client type for the reqwest backend.
ReqwestClientBuilder
Client builder type for the reqwest backend.
ReqwestRequestBuilder
Request builder type for the reqwest backend.
ReqwestResponse
HTTP response type for the reqwest backend.
Response
Default HTTP response type alias for the enabled backend.
SimulatorClient
HTTP client type for the simulator backend.
SimulatorClientBuilder
Client builder type for the simulator backend.
SimulatorRequestBuilder
Request builder type for the simulator backend.
SimulatorResponse
HTTP response type for the simulator backend.