Skip to the page

Reference · SDKs

Rust

Generate a typed Rust client for your deployed queries with progenitor, and call the rest of the Project API over standard HTTP.

In the schema
—

Installation and generation#

Run napalm generate from your project folder after you write your query files. The SDKs overview covers the generated files and how deployed queries are called.

Deployed query codegen

Generated clients call named deployed queries so production endpoints can disable passthrough.

The Rust client uses Oxide’s progenitor proc-macro, so cargo build compiles openapi.json directly into typed Rust structs and async methods.

Install once
cargo add progenitor futures serde_jsoncargo add serde --features derivecargo add reqwest --features json,streamcargo add uuid chrono --features uuid/serde,chrono/serde
src/main.rs
mod queries;mod session; progenitor::generate_api!(    spec = "napalm/openapi.json",    inner_type = session::Session,    pre_hook = session::carry,    post_hook = session::keep,); let mut headers = reqwest::header::HeaderMap::new();headers.insert(reqwest::header::AUTHORIZATION, format!("Bearer {session}").parse()?);let db = Client::new_with_client(    "https://<label>.napalmdata.com",    reqwest::Client::builder().default_headers(headers).build()?,    session::Session::new("https://<label>.napalmdata.com"),); let found = db    .get_note(None, &types::GetNoteRequest {        query: queries::GET_NOTE.into(),        variables: types::GetNoteVariables { id },    })    .await?;

Causal bookmarks across replicas#

Every query response returns a Napalm-Bookmark header with the shard’s commit position. Echoing that bookmark on subsequent requests guarantees read-your-own-writes consistency across every engine and replica. napalm generate emits a Session transport helper alongside your generated client. Attach that helper once so every call sends the latest bookmark and records updated bookmarks automatically. See Causal bookmarks.

src/bookmarks.rs
mod queries;mod session; progenitor::generate_api!(    spec = "napalm/openapi.json",    inner_type = session::Session,    pre_hook = session::carry,    post_hook = session::keep,); // napalm generate emits session.rs alongside the client so pre_hook and post_hook track Napalm-Bookmark.let session = session::Session::new("https://<label>.napalmdata.com");let db = Client::new_with_client("https://<label>.napalmdata.com", http, session.clone()); db.add_note(None, &types::AddNoteRequest {    query: queries::ADD_NOTE.into(),    variables: types::AddNoteVariables { title: "Plan".into() },}).await?;// Subsequent reads observe the new note on every replica.let found = db    .get_note(None, &types::GetNoteRequest {        query: queries::GET_NOTE.into(),        variables: types::GetNoteVariables { id: note_id },    })    .await?; // Merge an external bookmark (such as a webhook's Napalm-Position) into the session.session.reach(&position);

Sign-in#

Authenticate end users through your project’s sign-in routes. Redirect OAuth users to GET /sign-in/authorize with a SHA-256 PKCE challenge, or POST the challenge to an email/password, magic-link or WebAuthn passkey route. Every factor returns a one-time authorization code that you exchange with your PKCE verifier at GET /sign-in/token for a bearer session.

Exchange the authorization code · Rust
#[tokio::main]async fn main() -> Result<(), Box<dyn std::error::Error>> {    let code = std::env::var("CODE")?;    let verifier = std::env::var("VERIFIER")?;     let response = reqwest::Client::new()        .get(format!(            "https://notes.napalmdata.com/sign-in/token?code={code}&verifier={verifier}"        ))        .send()        .await?;    println!("{}", response.text().await?);    Ok(())}

Live queries#

Open a multiplexed Server-Sent Events stream at POST /subscribe. Initial snapshots arrive in result frames and subsequent commits emit incremental diffs in patch frames, both filtered by the caller’s access policies. Persist the latest lsn token to resume monotonically on reconnect. See Live queries for frame schemas and dynamic subscription changes.

Open a live stream · Rust
use serde_json::json; #[tokio::main]async fn main() -> Result<(), Box<dyn std::error::Error>> {    let session = std::env::var("SESSION")?;     let mut response = reqwest::Client::new()        .post("https://notes.napalmdata.com/subscribe")        .header("Authorization", format!("Bearer {session}"))        .json(&json!({            "subscriptions": [                {                    "id": "notes",                    "query": "select Note { title, done } filter .owner = global caller order by .title"                },                {                    "id": "note",                    "name": "getNote",                    "variables": {                        "id": "8f2c1e64-0b7a-4f4e-9d2b-3a6c5e1f7d90"                    }                }            ]        }))        .send()        .await?;    while let Some(chunk) = response.chunk().await? {        print!("{}", String::from_utf8_lossy(&chunk));    }    Ok(())}

Webhooks#

When you attach a webhook to a schema notify trigger, Napalm POSTs a signed payload whenever matching writes commit. Compute the HMAC-SHA256 hex digest of the raw request body with your signing secret and compare it in constant time against Napalm-Signature after stripping sha256=. Pass the Napalm-Position header to your session helper’s reach method so replica reads observe at least the commit that triggered the webhook. Acknowledge promptly with a 2xx status. Full payload schemas are in /openapi.yaml.

src/webhook.rs
use hmac::{Hmac, Mac};use sha2::Sha256; pub fn verify_webhook(raw_body: &[u8], signature: &str, secret: &[u8]) -> Result<(), &'static str> {    let hex_sig = signature.strip_prefix("sha256=").ok_or("missing sha256= prefix")?;    let bytes = hex::decode(hex_sig).map_err(|_| "malformed signature")?;    let mut mac = Hmac::<Sha256>::new_from_slice(secret).map_err(|_| "invalid secret")?;    mac.update(raw_body);    mac.verify_slice(&bytes).map_err(|_| "invalid Napalm-Signature")}

The change log#

GET /changes pages through committed transactions from the branch’s change log under the caller’s read access policies. Start from an RFC 3339 timestamp with since, then pass each page’s next bookmark back as after. Delivery is at-least-once, so persist your cursor after processing each page. See Notifications & webhooks for gap handling and webhook-driven tailing.

Read the change log · Rust
#[tokio::main]async fn main() -> Result<(), Box<dyn std::error::Error>> {    let napalm_key = std::env::var("NAPALM_KEY")?;     let response = reqwest::Client::new()        .get("https://notes.napalmdata.com/changes?since=2026-11-08T00:00:00Z&types=Note&limit=100")        .header("Authorization", format!("Bearer {napalm_key}"))        .send()        .await?;    println!("{}", response.text().await?);    Ok(())}

File uploads#

A mutation that sets file_size returns a one-time file_upload descriptor containing a presigned PUT url and required headers. For multipart uploads, the descriptor returns part_size and part_count instead, and POST /uploads/parts issues presigned part URLs.

Create the file record · Rust
use serde_json::json; #[tokio::main]async fn main() -> Result<(), Box<dyn std::error::Error>> {    let session = std::env::var("SESSION")?;     let response = reqwest::Client::new()        .post("https://notes.napalmdata.com/query")        .header("Authorization", format!("Bearer {session}"))        .json(&json!({            "query": "select (insert Scan { owner := global caller, file_name := <str>$name, file_size := <int64>$size }) { id, file_upload }",            "variables": {                "name": "lease.pdf",                "size": 2431604            }        }))        .send()        .await?;    println!("{}", response.text().await?);    Ok(())}

Upload the raw bytes to url with the returned headers, then call POST /uploads/complete to verify the stored byte length and magic-byte format and mark the record Ready. See File uploads for multipart transfers and error codes.

Complete and verify the upload · Rust
use serde_json::json; #[tokio::main]async fn main() -> Result<(), Box<dyn std::error::Error>> {    let session = std::env::var("SESSION")?;     let response = reqwest::Client::new()        .post("https://notes.napalmdata.com/uploads/complete")        .header("Authorization", format!("Bearer {session}"))        .json(&json!({            "token": "up_Y4_FLCcYYXRfsAgv1nz3jN2…"        }))        .send()        .await?;    println!("{}", response.text().await?);    Ok(())}

Search and questions#

POST /search ranks objects of one type by combined semantic and keyword relevance. POST /ask synthesizes a single EdgeQL statement for a natural-language question and runs it read-only. Both routes execute under the caller’s access rules.

Search · Rust
use serde_json::json; #[tokio::main]async fn main() -> Result<(), Box<dyn std::error::Error>> {    let session = std::env::var("SESSION")?;     let response = reqwest::Client::new()        .post("https://notes.napalmdata.com/search")        .header("Authorization", format!("Bearer {session}"))        .json(&json!({            "type": "Note",            "query": "launch timeline and milestones",            "limit": 5        }))        .send()        .await?;    println!("{}", response.text().await?);    Ok(())}
Ask · Rust
use serde_json::json; #[tokio::main]async fn main() -> Result<(), Box<dyn std::error::Error>> {    let session = std::env::var("SESSION")?;     let response = reqwest::Client::new()        .post("https://notes.napalmdata.com/ask")        .header("Authorization", format!("Bearer {session}"))        .json(&json!({            "question": "Which of my notes mention the launch?"        }))        .send()        .await?;    println!("{}", response.text().await?);    Ok(())}

Type a word or two to search every docs page.