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, and acts on the project the key belongs to.
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")?)?;VoidhashClient::new takes the secret key, and VoidhashClient::builder() takes these settings
too:
let voidhash = VoidhashClient::builder()
.secret_key(std::env::var("VOIDHASH_SECRET_KEY")?)
.project_id("proj_...")
.build()?;| Builder method | Default | Description |
|---|---|---|
.secret_key | none | Required. The client sends it as Authorization: Bearer <secret key>. |
.project_id | the key's project | The project every call acts on. Set it to skip looking it up. |
.base_url | https://api.voidhash.com | Overrides the API origin. |
.header | none | Adds an extra header to every request from this client. |
Building the client validates its input right away and makes no request. It returns
voidhash::Error::Request when the secret key or project id is blank, or .header was given
Authorization or x-secret-key in any casing.
A secret key belongs to one project, so you never pass the project's id to a method. Without
.project_id, the client reads the key's project from
GET /api/v1/session on the first call that needs it
and keeps it for the client's lifetime. When the credential can use several projects, set
.project_id; otherwise those calls return voidhash::Error::Request asking you to.
Create one client and share it across your handlers, for example in an Arc.
With the client configured, continue with checking access or receiving webhooks.
Resource methods
Each API resource is a method on the client, such as persons() or webhooks(), and the resources
mirror the API reference. The example below checks a perk through persons().
let has_premium = voidhash
.persons()
.has_active_perk("user_123", None, Some("premium"))
.await?;Every method is an async fn that returns Result<T, voidhash::Error>. The T is deserialized
into a typed struct generated from the API schemas, so there is no manual JSON unwrapping.