pub struct HaystackClient<T: Transport> { /* private fields */ }Expand description
A client for communicating with a Haystack HTTP API server.
Provides typed methods for all standard Haystack ops (about, read, hisRead,
etc.) as well as a generic call method for custom ops.
Supports both HTTP and WebSocket transports.
Implementations§
Source§impl HaystackClient<HttpTransport>
impl HaystackClient<HttpTransport>
Sourcepub async fn connect(
url: &str,
username: &str,
password: &str,
) -> Result<Self, ClientError>
pub async fn connect( url: &str, username: &str, password: &str, ) -> Result<Self, ClientError>
Connect to a Haystack server via HTTP, performing SCRAM authentication.
§Arguments
url- The server API root (e.g.http://localhost:8080/api)username- The username to authenticate aspassword- The user’s plaintext password
Sourcepub async fn connect_with_tls(
url: &str,
username: &str,
password: &str,
tls: &TlsConfig,
) -> Result<Self, ClientError>
pub async fn connect_with_tls( url: &str, username: &str, password: &str, tls: &TlsConfig, ) -> Result<Self, ClientError>
Connect to a Haystack server via HTTP with mutual TLS (mTLS) client certificate authentication, then perform SCRAM authentication.
Builds a custom reqwest::Client configured with the provided TLS
identity (client certificate + key) and optional CA certificate, then
runs the standard SCRAM handshake over that client.
§Arguments
url- The server API root (e.g.https://localhost:8443/api)username- The username to authenticate aspassword- The user’s plaintext passwordtls- The mTLS configuration (cert, key, optional CA)
Source§impl HaystackClient<WsTransport>
impl HaystackClient<WsTransport>
Sourcepub async fn connect_ws(
url: &str,
ws_url: &str,
username: &str,
password: &str,
) -> Result<Self, ClientError>
pub async fn connect_ws( url: &str, ws_url: &str, username: &str, password: &str, ) -> Result<Self, ClientError>
Connect to a Haystack server via WebSocket.
Performs SCRAM authentication over HTTP first to obtain an auth token, then establishes a WebSocket connection using that token.
§Arguments
url- The server API root for HTTP auth (e.g.http://localhost:8080/api)ws_url- The WebSocket URL (e.g.ws://localhost:8080/api/ws)username- The username to authenticate aspassword- The user’s plaintext password
Source§impl<T: Transport> HaystackClient<T>
impl<T: Transport> HaystackClient<T>
Sourcepub fn from_transport(transport: T) -> Self
pub fn from_transport(transport: T) -> Self
Create a client with an already-configured transport.
Sourcepub async fn call(&self, op: &str, req: &HGrid) -> Result<HGrid, ClientError>
pub async fn call(&self, op: &str, req: &HGrid) -> Result<HGrid, ClientError>
Call a raw Haystack op with a request grid.
Sourcepub async fn about(&self) -> Result<HGrid, ClientError>
pub async fn about(&self) -> Result<HGrid, ClientError>
Call the about op. Returns server information.
Sourcepub async fn ops(&self) -> Result<HGrid, ClientError>
pub async fn ops(&self) -> Result<HGrid, ClientError>
Call the ops op. Returns the list of operations supported by the server.
Sourcepub async fn formats(&self) -> Result<HGrid, ClientError>
pub async fn formats(&self) -> Result<HGrid, ClientError>
Call the formats op. Returns the list of MIME formats supported by the server.
Sourcepub async fn libs(&self) -> Result<HGrid, ClientError>
pub async fn libs(&self) -> Result<HGrid, ClientError>
Call the libs op. Returns the library modules installed on the server.
Sourcepub async fn read(
&self,
filter: &str,
limit: Option<usize>,
) -> Result<HGrid, ClientError>
pub async fn read( &self, filter: &str, limit: Option<usize>, ) -> Result<HGrid, ClientError>
Call the read op with a filter expression and optional limit.
Sourcepub async fn read_by_ids(&self, ids: &[&str]) -> Result<HGrid, ClientError>
pub async fn read_by_ids(&self, ids: &[&str]) -> Result<HGrid, ClientError>
Call the read op with a list of entity ids.
Call the nav op. If nav_id is None, returns the root navigation tree.
Sourcepub async fn defs(&self, filter: Option<&str>) -> Result<HGrid, ClientError>
pub async fn defs(&self, filter: Option<&str>) -> Result<HGrid, ClientError>
Call the defs op with an optional filter.
Sourcepub async fn watch_sub(
&self,
ids: &[&str],
lease: Option<&str>,
) -> Result<HGrid, ClientError>
pub async fn watch_sub( &self, ids: &[&str], lease: Option<&str>, ) -> Result<HGrid, ClientError>
Call the watchSub op to subscribe to a set of entity ids.
lease is an optional lease duration (e.g. "1min").
Sourcepub async fn watch_poll(&self, watch_id: &str) -> Result<HGrid, ClientError>
pub async fn watch_poll(&self, watch_id: &str) -> Result<HGrid, ClientError>
Call the watchPoll op to poll a watch for changes.
Sourcepub async fn watch_unsub(
&self,
watch_id: &str,
ids: &[&str],
) -> Result<HGrid, ClientError>
pub async fn watch_unsub( &self, watch_id: &str, ids: &[&str], ) -> Result<HGrid, ClientError>
Call the watchUnsub op to unsubscribe from a watch.
Sourcepub async fn point_write(
&self,
id: &str,
level: u8,
val: Kind,
) -> Result<HGrid, ClientError>
pub async fn point_write( &self, id: &str, level: u8, val: Kind, ) -> Result<HGrid, ClientError>
Call the pointWrite op to write a value to a writable point.
Sourcepub async fn his_read(
&self,
id: &str,
range: &str,
) -> Result<HGrid, ClientError>
pub async fn his_read( &self, id: &str, range: &str, ) -> Result<HGrid, ClientError>
Call the hisRead op to read historical data for a point.
range is a Haystack date range string (e.g. "today", "yesterday",
"2024-01-01,2024-01-31").
Sourcepub async fn his_write(
&self,
id: &str,
items: Vec<HDict>,
) -> Result<HGrid, ClientError>
pub async fn his_write( &self, id: &str, items: Vec<HDict>, ) -> Result<HGrid, ClientError>
Call the hisWrite op to write historical data for a point.
items should be dicts with ts and val tags.
Sourcepub async fn invoke_action(
&self,
id: &str,
action: &str,
args: HDict,
) -> Result<HGrid, ClientError>
pub async fn invoke_action( &self, id: &str, action: &str, args: HDict, ) -> Result<HGrid, ClientError>
Call the invokeAction op to invoke an action on an entity.
Sourcepub async fn close_session(&self) -> Result<HGrid, ClientError>
pub async fn close_session(&self) -> Result<HGrid, ClientError>
Call the close op to close the current server session.
This is distinct from close which shuts down the
underlying transport connection.
Sourcepub async fn specs(&self, lib: Option<&str>) -> Result<HGrid, ClientError>
pub async fn specs(&self, lib: Option<&str>) -> Result<HGrid, ClientError>
List all specs, optionally filtered by library name.
Sourcepub async fn spec(&self, qname: &str) -> Result<HGrid, ClientError>
pub async fn spec(&self, qname: &str) -> Result<HGrid, ClientError>
Get a single spec by qualified name.
Sourcepub async fn load_lib(
&self,
name: &str,
source: &str,
) -> Result<HGrid, ClientError>
pub async fn load_lib( &self, name: &str, source: &str, ) -> Result<HGrid, ClientError>
Load a Xeto library from source text.
Sourcepub async fn unload_lib(&self, name: &str) -> Result<HGrid, ClientError>
pub async fn unload_lib(&self, name: &str) -> Result<HGrid, ClientError>
Unload a library by name.
Sourcepub async fn export_lib(&self, name: &str) -> Result<HGrid, ClientError>
pub async fn export_lib(&self, name: &str) -> Result<HGrid, ClientError>
Export a library to Xeto source text.
Sourcepub async fn validate(&self, entities: Vec<HDict>) -> Result<HGrid, ClientError>
pub async fn validate(&self, entities: Vec<HDict>) -> Result<HGrid, ClientError>
Validate entities against the server’s ontology.
Sourcepub async fn close(&self) -> Result<(), ClientError>
pub async fn close(&self) -> Result<(), ClientError>
Close the transport connection.