pub struct Client { /* private fields */ }Expand description
Async HTTP client for running queries against a Helix instance.
A thin async wrapper over reqwest that knows how to reach a Helix
gateway’s query routes. Construct it with Client::new, optionally attach
a bearer API key via Client::with_api_key, then build and send requests
through Client::query.
The client is cheap to Clone — the underlying reqwest::Client shares
its connection pool — so a single instance can be reused across tasks.
Reachable as helix_db::Client.
§Examples
use helix_db::Client;
// Defaults to http://localhost:6969 when the URL is `None`.
let local = Client::new(None)?;
// Or point at a remote cluster and attach an API key.
let remote = Client::new(Some("https://cluster.helix-db.com"))?
.with_api_key(Some("hx_your_api_key"));Implementations§
Source§impl Client
impl Client
Sourcepub fn new(url: Option<&str>) -> Result<Self, HelixError>
pub fn new(url: Option<&str>) -> Result<Self, HelixError>
Create a client pointed at a Helix instance.
url is the instance base URL; when None, it defaults to
http://localhost:6969. The /v1/query base route is resolved up front
and reused by every request — dynamic queries POST to it directly and
stored queries append /<name>.
§Errors
Returns HelixError::InvalidURL if url (or the resolved query route)
cannot be parsed.
Sourcepub fn with_api_key(self, api_key: Option<&str>) -> Self
pub fn with_api_key(self, api_key: Option<&str>) -> Self
Attach (or clear) the bearer API key sent with every request.
Passing Some(key) sets an Authorization: Bearer <key> header on each
request; passing None clears any previously set key.
Sourcepub fn query<R: for<'de> Deserialize<'de>>(&self) -> QueryBuilder<'_, '_, R>
pub fn query<R: for<'de> Deserialize<'de>>(&self) -> QueryBuilder<'_, '_, R>
Start building a request.
R is the type the JSON response body is deserialized into by
QueryRequest::send. Returns a QueryBuilder on which you can toggle
request headers, then pick a query kind with QueryBuilder::dynamic or
QueryBuilder::stored.
§Examples
use helix_db::Client;
use helix_db::dsl::prelude::*;
use serde::Deserialize;
#[derive(Deserialize)]
struct Users { count: u64 }
let response: Users = client.query().dynamic(request).send().await?;