pub struct NodeConfig { /* private fields */ }Expand description
Configuration for a single Typesense node.
Use this to customize the HTTP client for specific nodes, for example to add custom TLS root certificates or configure proxies.
For simple cases, you can pass a plain URL string to the builder’s
.nodes() method, which will be automatically converted.
§Examples
use typesense::NodeConfig;
// Simple URL (same as passing a string directly)
let node = NodeConfig::new("https://node1.example.com");
// With custom HTTP client configuration
// (add timeouts, headers, TLS, etc. on native targets)
let node = NodeConfig::new("https://node2.example.com")
.http_builder(|builder| {
// This closure receives a `reqwest::ClientBuilder` and must return it.
// You can call any supported builder methods here; for example,
// `builder.connect_timeout(...)` on native targets.
builder
});Implementations§
Source§impl NodeConfig
impl NodeConfig
Sourcepub fn http_builder(
self,
f: impl FnOnce(ClientBuilder) -> ClientBuilder + 'static,
) -> Self
pub fn http_builder( self, f: impl FnOnce(ClientBuilder) -> ClientBuilder + 'static, ) -> Self
Sets a custom HTTP client builder for this node.
The closure receives a default reqwest::ClientBuilder and should return
a configured builder. This is useful for adding custom TLS certificates,
proxies, or other reqwest settings.
When not set, a default builder with a 5-second connect timeout is used (native targets only; WASM uses the browser’s defaults).
§Examples
#[cfg(not(target_family = "wasm"))]
{
use typesense::NodeConfig;
let cert = cert();
// You can capture arbitrary configuration here (certs, proxies, etc.)
// and apply it to the `reqwest::ClientBuilder` on platforms that support it.
let node = NodeConfig::new("https://secure.example.com")
.http_builder(move |builder| {
builder
.add_root_certificate(cert)
.connect_timeout(std::time::Duration::from_secs(10))
});
}§Multiple nodes with the same configuration
The closure is FnOnce, so it is consumed when the HTTP client for that node
is built. To use the same configuration (e.g. the same TLS certificate) for
multiple nodes, clone the value once per node when building the configs:
#[cfg(not(target_family = "wasm"))]
{
use typesense::{Client, NodeConfig};
let cert = cert();
let nodes = ["https://node1:8108", "https://node2:8108"]
.into_iter()
.map(|url| {
let cert_for_node = cert.clone();
NodeConfig::new(url).http_builder(move |b| {
b.add_root_certificate(cert_for_node)
})
})
.collect::<Vec<_>>();
let _client = Client::builder().nodes(nodes).api_key("key").build();
}