Reference · SDKs
Rust
Call your deployed queries through the client progenitor generates, and the rest of your project’s API over plain 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 and passthrough lockdown
napalm generate --deployed binds your ecosystem’s OpenAPI client to named /query/{name} routes so production endpoints can lock passthrough to keys or none.
The Rust client uses Oxide’s progenitor proc-macro, so cargo build compiles openapi.json directly into typed Rust structs and async methods.
cargo add progenitor futures serde_jsoncargo add serde --features derivecargo add reqwest --features json,streamcargo add uuid chrono --features uuid/serde,chrono/serdemod 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 answer returns a Napalm-Bookmark header marking the commit position on the shard. A read that sends the bookmark back never returns rows older than the caller’s own write, on any replica. napalm generate writes a session helper beside the client. Wire that helper into the client once so every call sends the latest bookmark and records updated bookmarks from responses. See Causal bookmarks.
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 writes session.rs beside the client. The macro's hooks send every call through the session.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?;// The read includes the new note on any replica.let found = db .get_note(None, &types::GetNoteRequest { query: queries::GET_NOTE.into(), variables: types::GetNoteVariables { id: note_id }, }) .await?; // session.reach joins a webhook's Napalm-Position into the session.session.reach(&position);Sign-in#
People sign in through your project’s sign-in routes. Start a provider’s sign-in at GET /sign-in/authorize with a PKCE challenge, or post the challenge to an email, code or passkey route. Every route ends in an authorization code. Trade the code and the verifier for a session token, and send that token as the bearer on every call.
#[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 stream at POST /subscribe and read it as Server-Sent Events. A result frame carries each query’s rows, and a patch frame carries the rows a commit changed. The caller’s access rules filter both frames. Keep each frame’s lsn to reconnect where the stream left off. See Live queries for every frame, adding and dropping subscriptions and reconnecting.
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=. Give the Napalm-Position header to the session’s reach so replica reads include the commit that fired the webhook. Acknowledge promptly with a 2xx status. Full payload schemas are in /openapi.yaml.
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 reads a branch’s committed rows from the change log one page at a time. The caller’s access rules filter the rows. Start from a time with since, then send each page’s next back as after. Delivery is at least once, so save the cursor after you handle a page, not before. See Notifications & webhooks for gaps and for tailing the log from a webhook’s position.
#[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 query that sets a file’s size returns a file_upload once. The descriptor holds a presigned PUT url and the headers to send with the PUT. For a large file, the descriptor holds a part_size and part_count instead, and part URLs come from POST /uploads/parts.
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(())}PUT the bytes to that url with those headers, then finish the upload. POST /uploads/complete checks the stored size, reads the format from the first bytes and marks the file Ready. See File uploads for parts.
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.
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(())}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(())}