Skip to guide
AvailKit/ developers
Browse documentation

Rust SDK

Typed Rust integration with explicit workspace authority, bounded requests and retained original booking intents.

On this page

Install without a private checkout

availkit-sdk 0.1.1. Rust 1.90 or newer, edition 2024. Cargo resolves the pinned transport and serialization dependencies. These are hosted distributions; availability on a public registry is not claimed.

Download the package or complete example project. Installation commands come from its shipped README. Verify the relevant entry in SHA256SUMS before use; the archive includes its license, support policy and full instructions.

Shell
curl --fail --proto '=https' -O https://availkit.dev/downloads/availkit-sdk-0.1.1.crate
curl --fail --proto '=https' -O https://availkit.dev/downloads/SHA256SUMS
sha256sum --check --ignore-missing SHA256SUMS
mkdir -p vendor
tar -xzf availkit-sdk-0.1.1.crate -C vendor

Configure trusted server authority

For backend examples, prepare an owned test workspace, a resource with hours and an offering with at least two available times. Issue a test key with Read and Book. The key selects its real workspace/environment on the server; the client label cannot change that authority.

Keep the downloaded key in an owner-only file and the example config/intents in owned private directories outside source control. The package README names the exact fields or environment variables. Use actual future UTC dates, at most seven days apart. Never pass a credential as a command argument or put it in a browser/mobile app. The protected-file helpers have the platform limits documented in each package.

The following is taken from examples/first_booking.rs in the download. Complete the surrounding config and imports using that runnable project; it is not an account-enrollment flow.

Rust
// Bounded owner-only regular config, no symlink or command-line credential.
let config: Config =
    serde_json::from_slice(&private_files::read(path, 16384)?).map_err(|_| input_error())?;
let environment = match config.environment.as_str() {
    "test" => Environment::Test,
    _ => return Err(input_error()),
};
let client = Client::new(
    &config.workspace_id,
    environment,
    &config.credential,
    Options {
        base_url: config
            .base_url
            .unwrap_or_else(|| "https://api.availkit.com".into()),
        ..Default::default()
    },
)?;
let cancellation = CancellationToken::new();
let directory = std::path::Path::new(&config.intent_directory);
// Refuse EVERY rerun, including after loss or successful completion. Inspect
// retained intents/receipt manually; never unlink a latch to retry unknown work.
private_files::create(
    directory.join("lifecycle-started.json"),
    b"{\"version\":1,\"state\":\"started\"}",
)?;

Create, read, move and cancel once

The complete example first checks availability, retains an exclusive original intent before each send, and gates every later step on a confirmed acknowledgment. It reads the booking, moves it using the original expectedStart, then cancels that exact booking. Existing intent/latch files prevent a second invocation from creating a fresh booking after an uncertain run. The example creates no catalog data and performs no unrelated cleanup.

Rust
let times = client
    .availability(
        &cancellation,
        &AvailabilityQuery {
            offering_id: config.offering_id.clone(),
            from: config.from,
            to: config.to,
        },
    )
    .await?;
if times.slots.len() < 2 {
    return Err(input_error());
}
let first = &times.slots[0];
let second = &times.slots[1];
let intent = client.prepare_book(
    &BookingInput {
        offering_id: config.offering_id,
        start: first.start.clone(),
        customer_id: None,
    },
    &new_idempotency_key()?,
)?;
intent.save_private(directory.join("create.json"))?;
let booking = client.execute(&intent, &cancellation).await?;
client.get_booking(&cancellation, &booking.id).await?;
let move_intent = client.prepare_reschedule_booking(
    &booking.id,
    &RescheduleInput {
        expected_start: booking.start.clone(),
        start: second.start.clone(),
    },
    &new_idempotency_key()?,
)?;
move_intent.save_private(directory.join("move.json"))?;
let moved = client.execute(&move_intent, &cancellation).await?;
let cancel = client.prepare_cancel(&moved.id, &new_idempotency_key()?)?;
cancel.save_private(directory.join("cancel.json"))?;
client.execute(&cancel, &cancellation).await?;
// Keep the durable latch and every original even after success.
private_files::create(
    directory.join("completed.json"),
    b"{\"version\":1,\"state\":\"completed\"}",
)?;

After preparing the private configuration, run the example once from its documented directory:

Shell
AVAILKIT_CONFIG_FILE=/absolute/private/config.json cargo run --manifest-path vendor/availkit-sdk-0.1.1/Cargo.toml --example first_booking

Use a fresh private intent directory for a separately intended test. Never replace the directory or files to recover an unknown request.

Handle rejection and unknown outcomes

After any failure, stop and preserve the original private intent and acknowledged booking IDs. A lost, timed-out or malformed mutation response can follow a committed change. An unrecognized error response is also insufficient to prove rejection. Log only the SDK’s finite safe diagnostic fields; keep raw requests, headers, contact details, capabilities and private intent records out of logs.

A current read can show what exists; it cannot recover a missing acknowledgment or prove an unknown create never happened. Do not generate a replacement key or delete the example’s permanent latch to rerun it. Only booking create/move/cancel operations have an explicit original-intent replay contract, bounded by the server’s 24-hour receipt window and current authority. Loading or importing an intent never sends it. Follow the lost-response guide before a separately authorized identical replay. Catalog, customer, webhook and maintenance writes have no such replay guarantee.

All transports enforce a configured total request deadline and response-size cap, validate TLS, refuse redirects and disable SDK mutation retries. Cancellation after admission is unknown. Read the package policy before supplying a custom transport or platform persistence implementation.

Coverage and runtime policy

All 34 stable workspace operations and seven public booking operations are implemented. Requests/results use language-appropriate types and validate the maintained wire contract. Pagination is explicit and bounded by your application. Supported calls, minimum permissions, exact versions, tests and platform limits ship in coverage.json, the package README and runtime policy.

Account/passkey/session ceremonies and recovery are excluded. Mobile and browser code must use public capabilities or a narrowly authorized backend. See the authority matrix, backend setup and all SDKs.