Skip to content
Quickstarts

Rust quickstart

Call the /platform/v1 Infrastructure API with the generated forestvpn-console-api-client Rust crate.

forestvpn-console-api-client is the generated Rust client for the /platform/v1 plane, at forestvpn-sdk/crates/forestvpn-console-api-client in the ForestVPN repository — the same operations and models the API reference documents.

Honest distribution note: the crate is not on crates.io yet. You depend on it by path from a source checkout.

Prerequisites

  • The Rust toolchain (rustup.rs)
  • A checkout of the ForestVPN repository
  • A project API key (fvpn_v1_…) — see API keys

1. Create a crate with the path dependency

Cargo.toml
[package]
name = "forestvpn-rust-quickstart"
version = "0.1.0"
edition = "2021"
publish = false

[dependencies]
# The generated PLATFORM-plane client, straight from the source checkout.
# Adjust the path to wherever your project sits relative to the checkout.
forestvpn-console-api-client = { path = "../../../../forestvpn-sdk/crates/forestvpn-console-api-client" }
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }

# Standalone crate: keep it out of any surrounding Cargo workspace.
[workspace]

2. First call: list your API keys

src/main.rs
use forestvpn_console_api_client::apis::configuration::Configuration;
use forestvpn_console_api_client::apis::platform_api_keys_api::list_platform_api_keys;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut config = Configuration::new();
    config.base_path = "https://api.fvpn.net".to_owned();
    // A project API key (fvpn_v1_…) minted in the console. Project-bound.
    config.bearer_access_token = Some(std::env::var("FVPN_API_KEY")?);

    let project_id = std::env::var("FVPN_PROJECT_ID")?;
    let keys = list_platform_api_keys(&config, &project_id).await?;
    for key in keys {
        let last_used = key
            .last_used_at
            .flatten()
            .map(|t| t.to_rfc3339())
            .unwrap_or_else(|| "never".to_owned());
        println!("{} ({}) last used: {}", key.name, key.key_prefix, last_used);
    }
    Ok(())
}

As in every generated client, auth is the bare key (Authorization: Bearer fvpn_v1_…) and the project id travels as the X-Project-Id header. The key is project-bound — key and project id must agree, or the call is a 401.

3. Run

FVPN_API_KEY=fvpn_v1_… FVPN_PROJECT_ID=<your-project-uuid> cargo run

Expected output: one line per key — name, display prefix, and when it last authenticated a request.

Verified by

scripts/quickstart-verify/rust-client.shcargo checks this exact crate (the snippet above, byte for byte) against the path-dependency client on every CI run.