Expand description
HTTP client abstraction for CDK
This crate provides an HTTP client wrapper that abstracts the underlying HTTP library.
Using this crate allows other CDK crates to avoid direct dependencies on a specific backend.
Backend selection is feature-based: enable a native backend with bitreq
(default) or reqwest. The features are additive — when both are enabled,
reqwest takes precedence (see “Backend selection” below).
The default bitreq backend supports HTTP proxy URLs only. SOCKS proxy schemes
such as socks5h are supported only when this crate is built with the reqwest
feature.
§Backend selection
CDK library crates depend on HTTP capability, while this crate owns the concrete
backend choice. The bitreq backend is the default: any CDK crate that pulls in
HTTP support turns it on automatically. cdk-common/http enables bitreq, and
cdk’s wallet and mint features depend on it, so applications get a working
client out of the box — including with cdk --no-default-features --features wallet.
The backend features are additive: enabling both bitreq and reqwest
resolves to reqwest (a strict superset that adds SOCKS proxy and
invalid-certificate support), so feature unification across a dependency graph
never conflicts. To use reqwest, add an explicit dependency on this crate with
the reqwest feature — it takes precedence wherever it is enabled:
[dependencies]
cdk = { version = "0.17.0", features = ["wallet"] }
cdk-http-client = { version = "0.17.0", features = ["reqwest"] }When depending on this crate directly with --no-default-features, at least one
backend must be selected, or compilation fails with a clear error. To exercise the
reqwest backend in workspace checks:
cargo check -p cdk -p cdk-http-client --features cdk-http-client/reqwest§Example
use cdk_http_client::{HttpClient, Response};
use serde::Deserialize;
#[derive(Deserialize)]
struct ApiResponse {
message: String,
}
async fn example() -> Response<ApiResponse> {
let client = HttpClient::new();
client.fetch("https://api.example.com/data").await
}Modules§
- ws
- WebSocket client abstraction for CDK
Structs§
- Async
- Default async transport backed by the crate
HttpClient. - Bitreq
Request Builder - bitreq-based RequestBuilder wrapper
- Http
Client - HTTP client wrapper
- Http
Client Builder - HTTP client builder for configuring proxy and TLS settings
- RawResponse
- Raw HTTP response with status code and body access
- Request
Builder - HTTP request builder for complex requests
Enums§
- Http
Error - HTTP errors that can occur during requests
Traits§
- Transport
- Expected HTTP transport.
Functions§
- fetch
- Convenience function for simple GET requests
Type Aliases§
- Bitreq
Transport - Bitreq-backed transport implementation.
- Response
- HTTP Response type - generic over the body type R and error type E This is the primary return type for all HTTP operations