Rust library
A server-side client for the Voidhash REST API.
The mobile SDKs decide what to show on the device. They cannot protect anything a customer can reach by calling your API directly, such as an export endpoint or a paid model. Those checks belong on your server, and this library is how you make them.
The voidhash crate is a client for the Voidhash REST API. It authenticates every request with a
project secret key.
Install the crate
Add the crate to your project with Cargo.
cargo add voidhashThe crate needs Rust 1.75 or newer. The client is async-first and runs on any executor. The examples below use tokio.
Create a secret key
In Studio, open Settings → API Keys and create a secret key. The raw value is shown only once.
Store the key in an environment variable or your secret manager. A secret key grants full access to the project. Never put it in a mobile app, a web bundle, or a repository.
Create the client
Create one client with your secret key.
use voidhash::VoidhashClient;
let voidhash = VoidhashClient::new(std::env::var("VOIDHASH_SECRET_KEY")?)?;The client is configured through new and two builder methods.
| Builder method | Default | Description |
|---|---|---|
new | none | Takes the required secret key. The client sends it as x-secret-key. |
.base_url | https://api.voidhash.com | Overrides the API origin. The scheme must be http: or https:. |
.header | none | Adds an extra header to every request from this client. |
VoidhashClient::new validates its input right away rather than on the first request. It returns
VoidhashError::Configuration when the secret key is blank, the base URL is invalid, or .header
was given x-secret-key in any casing.
The client is cheap to clone because it holds an Arc internally. Create one and share it across
your handlers.
With the client configured, continue with checking access or receiving webhooks.
Resource methods
Each API resource is a field on the client, and the fields mirror the API reference. The example
below checks a perk through the entitlements resource.
use serde_json::json;
let has_premium = voidhash
.entitlements
.has_active_perk(&voidhash::HasActivePerk {
distinct_id: "user_123".into(),
perk: voidhash::PerkSelector::Slug("premium".into()),
})
.await?;Every method is an async fn that returns Result<T, VoidhashError>. The T is deserialized into
a typed struct, so there is no manual JSON unwrapping.