pub struct PubkyHttpClientBuilder { /* private fields */ }Expand description
Configures a PubkyHttpClient before construction.
Customize timeouts, user-agent, pkarr relays, and (WASM) testnet behavior.
Most code obtains this via PubkyHttpClient::builder(), which simply returns
PubkyHttpClientBuilder::default().
§Defaults
- Pkarr relays:
crate::pkarr::DEFAULT_RELAYS - HTTP request timeout: reqwest default (no global timeout) unless set via
Self::request_timeout - User-agent:
pubky.org@<crate-version>plus anySelf::user_agent_extra
§Example
use std::time::Duration;
let client = PubkyHttpClient::builder()
.request_timeout(Duration::from_secs(10))
.user_agent_extra("myapp/1.2.3")
.build()?;You can keep the default Pkarr relays or override them via the builder:
// Start from defaults; you can also supply your own entirely.
let mut b = PubkyHttpClient::builder();
b.pkarr(|p| p.relays(&["https://pkarr.example.net/"]).expect("infallible"));
let _client = b.build()?;Implementations§
Source§impl PubkyHttpClientBuilder
impl PubkyHttpClientBuilder
Sourcepub fn testnet(&mut self) -> &mut Self
pub fn testnet(&mut self) -> &mut Self
Configure this builder to talk to a local Pubky testnet on localhost.
Concretely:
- DHT bootstrap to the local testnet node at:
"localhost:6881" - PKARR relay base URL:
"http://localhost:15411" - WASM builds additionally remember the hostname when resolving
_pubky.<pk>targets.
§Examples
use pubky::PubkyHttpClient;
let client = PubkyHttpClient::builder()
.testnet()
.build()
.expect("testnet client");Sourcepub fn testnet_with_host(&mut self, host: &str) -> &mut Self
pub fn testnet_with_host(&mut self, host: &str) -> &mut Self
Configure this builder to talk to a Pubky testnet reachable at a custom host.
Use this when your testnet stack isn’t on localhost (e.g. running in Docker,
a remote VM, or LAN machine).
Concretely:
- DHT bootstrap peer:
"<host>:6881"(native only) - PKARR relay base:
"http://<host>:15411" - WASM remembers
<host>to adjust URL rewriting for the browser environment.
§Examples
use pubky::PubkyHttpClient;
let client = PubkyHttpClient::builder()
.testnet_with_host("192.168.1.50") // or "host.docker.internal"
.build()
.expect("testnet client");§Notes
- These ports come from
pubky_common::constants::testnet_ports::{ BOOTSTRAP, PKARR_RELAY }. - Ensure your testnet exposes them from that host (and they’re reachable from where this code runs).
§Panics
If the testnet cannot because the given host leads to an invalid relay URL.
Sourcepub fn pkarr<F>(&mut self, f: F) -> &mut Self
pub fn pkarr<F>(&mut self, f: F) -> &mut Self
Allows mutating the internal pkarr::ClientBuilder with a callback function.
Use this to influence PKARR resolution inputs (relays, bootstrap nodes, timeouts, etc.) before building the client. There are no per-request resolution knobs; configuration is done up front.
§Example
let client = PubkyHttpClient::builder()
.pkarr(|p| p
.relays(&["https://pkarr.example.net/"]).expect("infallible")
.bootstrap(&["dht.node.example:6881"])
)
.build()?;Sourcepub const fn request_timeout(&mut self, timeout: Duration) -> &mut Self
pub const fn request_timeout(&mut self, timeout: Duration) -> &mut Self
Set HTTP requests timeout.
Sourcepub fn user_agent_extra<S: Into<String>>(&mut self, extra: S) -> &mut Self
pub fn user_agent_extra<S: Into<String>>(&mut self, extra: S) -> &mut Self
Append an extra user-agent segment after the default pubky.org@<version>.
Enables app-level telemetry
Example: .user_agent_extra("myapp/1.2.3")
Sourcepub fn build(&self) -> Result<PubkyHttpClient, BuildError>
pub fn build(&self) -> Result<PubkyHttpClient, BuildError>
Build a PubkyHttpClient.
§Errors
crate::errors::BuildError::Pkarrif building the PKARR client fails.crate::errors::BuildError::Httpif constructing the HTTP client fails.
§Examples
let client = PubkyHttpClient::builder().build()?;Trait Implementations§
Source§impl Clone for PubkyHttpClientBuilder
impl Clone for PubkyHttpClientBuilder
Source§fn clone(&self) -> PubkyHttpClientBuilder
fn clone(&self) -> PubkyHttpClientBuilder
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more