Reference · SDKs
Kotlin
Generate a typed Kotlin client for your deployed queries with OpenAPI Generator, 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 Kotlin client uses the OpenAPI Generator Gradle plugin and writes Queries.kt beside openapi.json.
plugins { id("org.openapi.generator") version "7.10.0" } openApiGenerate { generatorName.set("kotlin") inputSpec.set("$projectDir/napalm/openapi.json") packageName.set("napalm.client")}import napalm.client.apis.DefaultApiimport napalm.client.infrastructure.ApiClientimport napalm.client.models.GetNoteRequestimport napalm.client.models.GetNoteVariables ApiClient.accessToken = sessionval db = DefaultApi("https://<label>.napalmdata.com") val found = db.getNote( GetNoteRequest( query = Queries.GET_NOTE, variables = GetNoteVariables(id = noteId), ))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.
// napalm generate emits Session.kt alongside the client as an OkHttp interceptor.val napalm = Session("https://<label>.napalmdata.com")val db = DefaultApi("https://<label>.napalmdata.com", OkHttpClient.Builder().addInterceptor(napalm).build()) db.addNote(AddNoteRequest(query = Queries.ADD_NOTE, variables = AddNoteVariables(title = "Plan")))// Subsequent reads observe the new note on every replica.val found = db.getNote(GetNoteRequest(query = Queries.GET_NOTE, variables = GetNoteVariables(id = noteId))) // Merge an external bookmark (such as a webhook's Napalm-Position) into the session.napalm.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.
import java.net.URIimport java.net.http.HttpClientimport java.net.http.HttpRequestimport java.net.http.HttpResponse fun main() { val code = System.getenv("CODE") ?: "" val verifier = System.getenv("VERIFIER") ?: "" val request = HttpRequest.newBuilder(URI.create("https://notes.napalmdata.com/sign-in/token?code=$code&verifier=$verifier")) .build() val response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString()) println(response.body())}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.
import java.net.URIimport java.net.http.HttpClientimport java.net.http.HttpRequestimport java.net.http.HttpResponse fun main() { val session = System.getenv("SESSION") ?: "" val request = HttpRequest.newBuilder(URI.create("https://notes.napalmdata.com/subscribe")) .header("Authorization", "Bearer $session") .header("Content-Type", "application/json") .POST( HttpRequest.BodyPublishers.ofString( """ { "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" } } ] } """.trimIndent(), ), ) .build() HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofLines()).body().forEach(::println)}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.
import java.security.MessageDigestimport javax.crypto.Macimport javax.crypto.spec.SecretKeySpec fun verifyWebhook(rawBody: ByteArray, signatureHeader: String, secret: ByteArray): Boolean { if (!signatureHeader.startsWith("sha256=")) return false val mac = Mac.getInstance("HmacSHA256").apply { init(SecretKeySpec(secret, "HmacSHA256")) } val expected = mac.doFinal(rawBody) val sent = signatureHeader.removePrefix("sha256=").hexToByteArray() return MessageDigest.isEqual(expected, sent)}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.
import java.net.URIimport java.net.http.HttpClientimport java.net.http.HttpRequestimport java.net.http.HttpResponse fun main() { val napalmKey = System.getenv("NAPALM_KEY") ?: "" val request = HttpRequest.newBuilder(URI.create("https://notes.napalmdata.com/changes?since=2026-11-08T00:00:00Z&types=Note&limit=100")) .header("Authorization", "Bearer $napalmKey") .build() val response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString()) println(response.body())}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.
import java.net.URIimport java.net.http.HttpClientimport java.net.http.HttpRequestimport java.net.http.HttpResponse fun main() { val session = System.getenv("SESSION") ?: "" val request = HttpRequest.newBuilder(URI.create("https://notes.napalmdata.com/query")) .header("Authorization", "Bearer $session") .header("Content-Type", "application/json") .POST( HttpRequest.BodyPublishers.ofString( """ { "query": "select (insert Scan { owner := global caller, file_name := <str>${'$'}name, file_size := <int64>${'$'}size }) { id, file_upload }", "variables": { "name": "lease.pdf", "size": 2431604 } } """.trimIndent(), ), ) .build() val response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString()) println(response.body())}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.
import java.net.URIimport java.net.http.HttpClientimport java.net.http.HttpRequestimport java.net.http.HttpResponse fun main() { val session = System.getenv("SESSION") ?: "" val request = HttpRequest.newBuilder(URI.create("https://notes.napalmdata.com/uploads/complete")) .header("Authorization", "Bearer $session") .header("Content-Type", "application/json") .POST( HttpRequest.BodyPublishers.ofString( """ { "token": "up_Y4_FLCcYYXRfsAgv1nz3jN2…" } """.trimIndent(), ), ) .build() val response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString()) println(response.body())}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.
import java.net.URIimport java.net.http.HttpClientimport java.net.http.HttpRequestimport java.net.http.HttpResponse fun main() { val session = System.getenv("SESSION") ?: "" val request = HttpRequest.newBuilder(URI.create("https://notes.napalmdata.com/search")) .header("Authorization", "Bearer $session") .header("Content-Type", "application/json") .POST( HttpRequest.BodyPublishers.ofString( """ { "type": "Note", "query": "launch timeline and milestones", "limit": 5 } """.trimIndent(), ), ) .build() val response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString()) println(response.body())}import java.net.URIimport java.net.http.HttpClientimport java.net.http.HttpRequestimport java.net.http.HttpResponse fun main() { val session = System.getenv("SESSION") ?: "" val request = HttpRequest.newBuilder(URI.create("https://notes.napalmdata.com/ask")) .header("Authorization", "Bearer $session") .header("Content-Type", "application/json") .POST( HttpRequest.BodyPublishers.ofString( """ { "question": "Which of my notes mention the launch?" } """.trimIndent(), ), ) .build() val response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString()) println(response.body())}