HTTP client abstraction for the Cashu Development Kit (CDK).
This crate provides an HTTP client wrapper and transport trait abstraction that allows other CDK crates to avoid direct dependencies on a specific backend.
bitreq(default) - enables the bitreq backend and transport implementationreqwest- enables the reqwest backend and transport implementationtor- enables the Tor transport implementation
Native builds must enable at least one HTTP backend: bitreq or reqwest.
bitreq is the default. cdk-common/http enables it, and cdk's wallet and
mint features depend on that, so any CDK build that uses HTTP gets a working
client out of the box — including cdk --no-default-features --features wallet.
Depending on this crate directly with --no-default-features and selecting no
backend is unsupported and fails at compile time with a clear error.
The backend features are additive. When both bitreq and reqwest are enabled,
reqwest takes precedence and is the single backend compiled in (it is a strict
superset, adding SOCKS proxy and invalid-certificate support). This means Cargo
feature unification across a dependency graph never produces a build conflict: a
crate that enables reqwest and another that enables bitreq resolve to
reqwest.
Use default bitreq backend:
cargo check -p cdk-http-clientUse reqwest backend (standalone):
cargo check -p cdk-http-client --no-default-features --features reqwestTo use the reqwest backend with CDK, add a direct cdk-http-client dependency
with the reqwest feature. It takes precedence wherever it is enabled, so there
is no need to disable default features:
[dependencies]
cdk = { version = "0.17.0", features = ["wallet"] }
cdk-http-client = { version = "0.17.0", features = ["reqwest"] }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
}get(url)- GET request builderpost(url)- POST request builderpatch(url)- PATCH request builder
fetch<R>(url)- simple GET returning JSONpost_json<B, R>(url, body)- POST with JSON bodypost_form<F, R>(url, form)- POST with form datapatch_json<B, R>(url, body)- PATCH with JSON body
Transport- trait consumed by higher-level CDK componentsAsync- default transport using the selected backendBitreqTransport- alias forAsyncwhenbitreqis selectedReqwestTransport- alias forAsyncwhenreqwestis enabledTorAsync- Tor-specific transport (enabled bytorfeature)