Reference · SDKs
Go
Generate a typed Go client for your deployed queries with oapi-codegen, 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.
--lang go runs oapi-codegen via go run and emits a self-contained Go package.
db, err := napalm.NewClientWithResponses("https://<label>.napalmdata.com", napalm.WithRequestEditorFn(func(ctx context.Context, req *http.Request) error { req.Header.Set("Authorization", "Bearer "+session) return nil })) // Pass a Napalm-Bookmark in params when you want read-your-own-writes across replicas.found, err := db.GetNoteWithResponse(ctx, nil, napalm.GetNoteJSONRequestBody{ Query: napalm.QueryGetNote, Variables: napalm.GetNoteVariables{Id: id},})// found.JSON200.Data holds typed rows, and found.JSON4XX holds structured API errors.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.go alongside the client to track Napalm-Bookmark headers.session := napalm.NewSession("https://<label>.napalmdata.com", nil)db, err := napalm.NewClientWithResponses("https://<label>.napalmdata.com", napalm.WithHTTPClient(session), napalm.WithRequestEditorFn(func(ctx context.Context, req *http.Request) error { req.Header.Set("Authorization", "Bearer "+token) return nil })) _, err = db.AddNoteWithResponse(ctx, nil, napalm.AddNoteJSONRequestBody{ Query: napalm.QueryAddNote, Variables: napalm.AddNoteVariables{Title: "Plan"},})// Subsequent reads observe the new note on every replica.found, err := db.GetNoteWithResponse(ctx, nil, napalm.GetNoteJSONRequestBody{ Query: napalm.QueryGetNote, Variables: napalm.GetNoteVariables{Id: noteID},}) // 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.
package main import ( "fmt" "io" "net/http" "os") func main() { code := os.Getenv("CODE") verifier := os.Getenv("VERIFIER") request, err := http.NewRequest("GET", "https://notes.napalmdata.com/sign-in/token?code="+code+"&verifier="+verifier, nil) if err != nil { panic(err) } response, err := http.DefaultClient.Do(request) if err != nil { panic(err) } defer response.Body.Close() answer, err := io.ReadAll(response.Body) if err != nil { panic(err) } fmt.Println(string(answer))}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.
package main import ( "bufio" "fmt" "net/http" "os" "strings") func main() { session := os.Getenv("SESSION") body := strings.NewReader(`{ "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" } } ]}`) request, err := http.NewRequest("POST", "https://notes.napalmdata.com/subscribe", body) if err != nil { panic(err) } request.Header.Set("Authorization", "Bearer "+session) request.Header.Set("Content-Type", "application/json") response, err := http.DefaultClient.Do(request) if err != nil { panic(err) } defer response.Body.Close() scanner := bufio.NewScanner(response.Body) for scanner.Scan() { fmt.Println(scanner.Text()) }}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.
func verifyWebhook(r *http.Request, secret []byte) ([]byte, string, error) { raw, err := io.ReadAll(r.Body) if err != nil { return nil, "", err } mac := hmac.New(sha256.New, secret) mac.Write(raw) sent, _ := hex.DecodeString(strings.TrimPrefix(r.Header.Get("Napalm-Signature"), "sha256=")) if !hmac.Equal(mac.Sum(nil), sent) { return nil, "", errors.New("invalid Napalm-Signature") } return raw, r.Header.Get("Napalm-Position"), nil}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.
package main import ( "fmt" "io" "net/http" "os") func main() { napalmKey := os.Getenv("NAPALM_KEY") request, err := http.NewRequest("GET", "https://notes.napalmdata.com/changes?since=2026-11-08T00:00:00Z&types=Note&limit=100", nil) if err != nil { panic(err) } request.Header.Set("Authorization", "Bearer "+napalmKey) response, err := http.DefaultClient.Do(request) if err != nil { panic(err) } defer response.Body.Close() answer, err := io.ReadAll(response.Body) if err != nil { panic(err) } fmt.Println(string(answer))}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.
package main import ( "fmt" "io" "net/http" "os" "strings") func main() { session := os.Getenv("SESSION") body := strings.NewReader(`{ "query": "select (insert Scan { owner := global caller, file_name := <str>$name, file_size := <int64>$size }) { id, file_upload }", "variables": { "name": "lease.pdf", "size": 2431604 }}`) request, err := http.NewRequest("POST", "https://notes.napalmdata.com/query", body) if err != nil { panic(err) } request.Header.Set("Authorization", "Bearer "+session) request.Header.Set("Content-Type", "application/json") response, err := http.DefaultClient.Do(request) if err != nil { panic(err) } defer response.Body.Close() answer, err := io.ReadAll(response.Body) if err != nil { panic(err) } fmt.Println(string(answer))}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.
package main import ( "fmt" "io" "net/http" "os" "strings") func main() { session := os.Getenv("SESSION") body := strings.NewReader(`{ "token": "up_Y4_FLCcYYXRfsAgv1nz3jN2…"}`) request, err := http.NewRequest("POST", "https://notes.napalmdata.com/uploads/complete", body) if err != nil { panic(err) } request.Header.Set("Authorization", "Bearer "+session) request.Header.Set("Content-Type", "application/json") response, err := http.DefaultClient.Do(request) if err != nil { panic(err) } defer response.Body.Close() answer, err := io.ReadAll(response.Body) if err != nil { panic(err) } fmt.Println(string(answer))}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.
package main import ( "fmt" "io" "net/http" "os" "strings") func main() { session := os.Getenv("SESSION") body := strings.NewReader(`{ "type": "Note", "query": "launch timeline and milestones", "limit": 5}`) request, err := http.NewRequest("POST", "https://notes.napalmdata.com/search", body) if err != nil { panic(err) } request.Header.Set("Authorization", "Bearer "+session) request.Header.Set("Content-Type", "application/json") response, err := http.DefaultClient.Do(request) if err != nil { panic(err) } defer response.Body.Close() answer, err := io.ReadAll(response.Body) if err != nil { panic(err) } fmt.Println(string(answer))}package main import ( "fmt" "io" "net/http" "os" "strings") func main() { session := os.Getenv("SESSION") body := strings.NewReader(`{ "question": "Which of my notes mention the launch?"}`) request, err := http.NewRequest("POST", "https://notes.napalmdata.com/ask", body) if err != nil { panic(err) } request.Header.Set("Authorization", "Bearer "+session) request.Header.Set("Content-Type", "application/json") response, err := http.DefaultClient.Do(request) if err != nil { panic(err) } defer response.Body.Close() answer, err := io.ReadAll(response.Body) if err != nil { panic(err) } fmt.Println(string(answer))}