HTTP JSON & REST Guide
Execute SpydQL, prepare statements, stream responses, and manage clusters across curl, JS, Python, Go, and Rust.
SpydDB's authenticated HTTP/1.1 listener (http_bind) provides query execution, prepared statements, full-text search, OpenTelemetry ingest, alerting, cluster orchestration, and online administration — enforcing the exact same TLS, RBAC, row policies, field masks, quotas, and SSI transactions as SpydWire.
Looking for interactive request/response schemas across every route? Open the Interactive OpenAPI Explorer.
Authentication & Database Routing#
Every route except GET /v1/health, /v1/auth/providers, /v1/auth/login, and /studio/* requires a Bearer token:
Authorization: Bearer <token>
X-Spyd-Database: analytics
X-Request-Id: req-01J9ABCDEF
X-Spyd-Cluster: eu-westX-Spyd-Databasetargets a specific database served by the node (omitting it selects the default database; an unknown database returns404 database_not_found).X-Spyd-Clusterforwards allowlisted Studio, query, APM, alert, and security-sync routes server-side to the named linked cluster (localor empty executes on the local server;X-Spyd-Proxy-Hop: 1blocks proxy loops).X-Spyd-Securitycarries the coordinator's statement security-rule fingerprint on distributed shard calls (409 security_mismatchfails closed on rule drift).X-Spyd-Cluster-Nameidentifies a reverse-dial publisher link onGET /v1/cluster/fleet/publish. See Multi-Cluster Fleet & Security Sync for full cluster header behavior.- The caller's
tenantalways derives authoritatively from the authenticated credential and cannot be overridden via headers. - Browser clients respect configured
http_cors_origins.
Tagged JSON Values#
HTTP payloads use SpydDB's unambiguous tagged value format so 64-bit unsigned IDs, exact fixed-point decimals, byte arrays, and nulls never suffer JSON coercion bugs:
| SpydDB Type | JSON Value Encoding |
|---|---|
Null | "Null" |
Bool | {"Bool": true} |
U64 / I64 | {"U64": 18446744073709551000} / {"I64": -42} |
F64 | {"F64": 99.5} |
Decimal | {"Decimal": {"mantissa": 1999, "scale": 2}} |
String / Text | {"String": "paid"} |
Timestamp / Date | {"Timestamp": 1735689600000000} / {"Date": 20089} |
Vector | {"Vector": [0.12, -0.45, 0.88]} |
GeoPoint | {"GeoPoint": {"lat": 37.7749, "lng": -122.4194}} |
Complete HTTP Examples Across Languages#
cURL (query, prepare, execute, search, cancel)#
# 1. Execute a parameterized SpydQL query
curl -sS --cacert tls/ca.crt https://localhost:8080/v1/query \
-H "Authorization: Bearer $SPYD_TOKEN" \
-H "X-Spyd-Database: default" \
-H "Content-Type: application/json" \
-d '{
"query_id": 1001,
"sql": "orders | where status == $1 and total >= cast($2 as decimal(12, 2)) | pick id, customer, total | take 10",
"parameters": [{"String": "paid"}, {"String": "100.00"}]
}'
# 2. Prepare once, execute repeatedly, close handle
PREP=$(curl -sS --cacert tls/ca.crt https://localhost:8080/v1/prepare \
-H "Authorization: Bearer $SPYD_TOKEN" \
-H "Content-Type: application/json" \
-d '{"sql": "orders | where customer_id == $1 | pick id, total"}')
STMT_ID=$(echo "$PREP" | jq -r '.statement_id')
curl -sS --cacert tls/ca.crt https://localhost:8080/v1/execute \
-H "Authorization: Bearer $SPYD_TOKEN" \
-H "Content-Type: application/json" \
-d "{\"statement_id\": $STMT_ID, \"parameters\": [{\"U64\": 42}]}"
curl -sS -X DELETE --cacert tls/ca.crt "https://localhost:8080/v1/prepared/$STMT_ID" \
-H "Authorization: Bearer $SPYD_TOKEN"
# 3. Cancel an in-flight query by client-chosen query_id
curl -sS -X POST --cacert tls/ca.crt https://localhost:8080/v1/cancel/1001 \
-H "Authorization: Bearer $SPYD_TOKEN"TypeScript / JavaScript (fetch)#
const token = process.env.SPYD_TOKEN!;
const res = await fetch("https://localhost:8080/v1/query", {
method: "POST",
headers: {
"Authorization": `Bearer ${token}`,
"Content-Type": "application/json",
"X-Spyd-Database": "default",
},
body: JSON.stringify({
sql: "orders | where status == $1 | pick id, customer, total | take 20",
parameters: [{ String: "paid" }],
}),
});
if (!res.ok) {
throw new Error(`SpydDB HTTP ${res.status}: ${await res.text()}`);
}
const data = await res.json();
console.log("Columns:", data.columns, "Rows:", data.rows);Python (httpx)#
import os
import httpx
with httpx.Client(
base_url="https://localhost:8080",
verify="tls/ca.crt",
headers={"Authorization": f"Bearer {os.environ['SPYD_TOKEN']}"},
timeout=30.0,
) as client:
# Query
q = client.post(
"/v1/query",
json={
"sql": "orders | where status == $1 | pick id, customer | take 10",
"parameters": [{"String": "paid"}],
},
)
q.raise_for_status()
print(q.json()["rows"])
# BM25 Search
s = client.post(
"/v1/search",
json={"query": "hardware delivery", "collections": ["orders"], "limit": 5},
)
s.raise_for_status()
print(s.json())Go (net/http)#
package main
import (
"bytes"
"crypto/tls"
"crypto/x509"
"encoding/json"
"fmt"
"net/http"
"os"
)
func main() {
caPEM, _ := os.ReadFile("tls/ca.crt")
pool := x509.NewCertPool()
pool.AppendCertsFromPEM(caPEM)
hc := &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{RootCAs: pool},
},
}
body, _ := json.Marshal(map[string]any{
"sql": "orders | where status == $1 | pick id, total | take 5",
"parameters": []map[string]any{{"String": "paid"}},
})
req, _ := http.NewRequest("POST", "https://localhost:8080/v1/query", bytes.NewReader(body))
req.Header.Set("Authorization", "Bearer "+os.Getenv("SPYD_TOKEN"))
req.Header.Set("Content-Type", "application/json")
resp, err := hc.Do(req)
if err != nil { panic(err) }
defer resp.Body.Close()
var out map[string]any
_ = json.NewDecoder(resp.Body).Decode(&out)
fmt.Println(out)
}Rust (reqwest)#
use serde_json::json;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let cert_bytes = std::fs::read("tls/ca.crt")?;
let cert = reqwest::Certificate::from_pem(&cert_bytes)?;
let client = reqwest::Client::builder()
.add_root_certificate(cert)
.build()?;
let resp: serde_json::Value = client
.post("https://localhost:8080/v1/query")
.bearer_auth(std::env::var("SPYD_TOKEN")?)
.json(&json!({
"sql": "orders | where status == $1 | take 10",
"parameters": [{ "String": "paid" }]
}))
.send()
.await?
.error_for_status()?
.json()
.await?;
println!("{resp:#}");
Ok(())
}Java (SpydClient HTTPS / JDK HttpClient)#
Prefer the official SpydClient builder in Java for built-in rotating tokens, CA trust verification, concurrency bounds, prepared-handle re-preparation, streaming decoding, and metrics.
Endpoint Summary#
Explore full request schemas, response payloads, and copyable SDK snippets for all HTTP routes — Query & Search, Auth, OTLP & APM, Alerting & SLOs, Cluster & Replication, and Online Admin — in the Interactive OpenAPI Explorer.