Skip to content
Contents

HTTP API

Rindle's public interface

The HTTP API is Rindle’s true interface. Every client and framework binding is a thin layer over these routes, and anything they do, you can do with plain HTTP. Most apps will use a client library for convenience, but that isn’t required. You can always drop down and call Rindle directly.

Every route your app uses is under /db/. Only the health checks are at the root.

Auth

Access to the HTTP API typically requires an API token. Send it using the standard Authorization header:

Authorization: Bearer <token>
  • Locally, there is no token unless you start with rindle up --token <token>. A server bound to 127.0.0.1 with no token accepts every request.
  • On any other address, Rindle won’t start without a token.

A wrong or missing token is 401.

The operator routes — /admin/*, /re-bootstrap, /shed, /stats — take a second credential, adminToken, so the token your app server holds cannot also restart the daemon.

Responses

Success bodies are JSON. Write responses carry a commit_cursor, the position of that write in the log, and a routing object:

{
  "result": { … },
  "commit_cursor": "w:00000000000000a3",
  "routing": {
    "served_by": "authority",
    "applied_lag_ms": null,
    "fence_fallback": false
  }
}

served_by is the server’s posture — authority or follower. On an authority the other two are always null and false, and that is the honest answer rather than a placeholder: an authority has no upstream to lag behind, and it is the fence, so there is nothing to fall back to. A read answers commit_cursor: null, since it committed nothing.

An error body carries the message:

{
  "error": "unsupported: `SET size = …` over a column. Read the row, compute, and write the value …"
}

A refusal says what to write instead, not which case it failed to match, because the message is what you read at the moment the statement will not run. Inside a transaction, two more fields ride along: transaction_state, "open" or "closed", and retry_scope. A failed read leaves the transaction open — it changed nothing — where a failed write closes it, and that difference is the one a caller acts on. retry_scope: "never" means asking again cannot help. Two errors also carry a code: TRANSACTION_CLOSED (410) and TRANSACTION_OPERATION_SEQUENCE (409).

Status Meaning
400 Bad request, or SQL outside the subset. The message names the rewrite.
401 / 403 Wrong API token, or no API token on a public address.
409 A conflict: a migration re-sent with different changes, or an out-of-sequence transaction op.
410 The transaction is gone — committed, rolled back, past its deadline, or lost to a restart.
429 The client is at its subscription limit.
503 Busy or starting up. Retry after the Retry-After header.

Every response has a Rindle-Boot-Id header that changes when the server restarts.

Server Routes

Called by your server, with the API token.

Every write is a subset of SQLite DML — INSERT … VALUES, ON CONFLICT, and an UPDATE/DELETE whose WHERE may be a predicate over the table’s own columns. rows_affected is the number of rows the WHERE matched. An expression, a pattern match or a subquery is refused with the rewrite named; SQL has the table and the reason.

batch

POST /db/batch. Runs statements in one transaction. All commit or none do.

{
  "statements": [
    {
      "sql": "INSERT INTO comment (issue_id, body) VALUES (?, ?)",
      "args": [1, "a"]
    },
    {
      "sql": "INSERT INTO comment (issue_id, body) VALUES (?, ?)",
      "args": [1, "b"]
    }
  ]
}

Returns { "results": [ … ] }, one per statement.

execute

POST /db/execute. Runs one statement.

{
  "statement": { "sql": "SELECT * FROM issue WHERE id = ?", "args": [1] }
}

Returns { "result": … }. Schema changes go through /db/migrate.

A SELECT here answers a rectangle — columns and rows, no nesting. A query with a WITH … OF clause is refused on this route by name; read it with query, which answers the tree. Statements run one at a time, in order, so a read in a batch sees the writes before it.

A script whose statements are all reads takes no transaction at all: it is answered from the store’s latest committed state, so it blocks no write and does not queue behind an open transaction — and it does not see one’s uncommitted writes either. A script that mixes reads and writes uses one private transaction, so a read sees earlier writes in that script. Only commit replay takes the writer. Hot application reads still belong on the live query plane, which keeps its answer up to date instead of recomputing it.

Statements

A statement is one SQL statement and its arguments:

{
  "sql": "INSERT INTO issue (id, title, closed) VALUES (?, ?, ?)",
  "args": ["i_01", "first", 0]
}
  • args is an array for ? placeholders, or an object for named ones (:title).
  • Values are JSON strings, numbers, booleans and null. Send 64-bit integers that don’t fit in a double as {"$rindle":"i64","value":"9007199254740993"}.
  • want_rows: false skips returning rows.

A statement result:

{
  "columns": [{ "name": "id", "decltype": "INTEGER" }],
  "rows": [[{ "$rindle": "i64", "value": "1" }]],
  "rows_affected": 0,
  "last_insert_rowid": null,
  "rows_read": null,
  "rows_written": null
}

rows are arrays in column order. Integers come back as {"$rindle":"i64","value":"…"}, so none lose precision.

Three of those fields are narrower than they look, and it is better to read it here than to discover it:

  • last_insert_rowid is always null. A paged store has no rowid, and a keyed statement names its own key — so there is no id for Rindle to hand back. Mint ids in your app.
  • rows_read and rows_written are always null. The keyed plane does not meter them.
  • rows_affected is real, and counts the rows the statement changed.

migrate

POST /db/migrate. Applies a schema change once, by name. Sending the same id again is a no-op.

{
  "id": "0001_init",
  "sql": "CREATE TABLE issue (id TEXT PRIMARY KEY, title TEXT);"
}

Returns { "applied": true, "commit_cursor": … }, or "applied": false if it was already applied. The id is the idempotency key and its checksum is over the parsed changes, so reformatting the SQL is free; sending a script that means something different under an applied id is 409. SQL has the DDL this accepts, and what it refuses.

query

POST /db/query. Runs a Rindle SQL query once and returns its result.

{
  "sql": "SELECT * FROM issue WHERE closed = ? ORDER BY id DESC LIMIT 50",
  "params": [0]
}

Or a builder query’s { "ast": … }. Returns { "rows": [ … ] }, in the shape a subscription delivers: a WITH … OF query’s rows carry their children.

stream-auth

POST /db/stream-auth. Returns a stream token for a client, to open its stream or keep it open.

POST /db/stream-auth
Authorization: Bearer $RINDLE_API_TOKEN
Rindle-Client: c_7f3k2q
Rindle-User: user_42
Rindle-Stream-Token: eyJjIjoiY183ZjNrMnEi…

Returns { "streamToken": "eyJjIjoiY183ZjNrMnEi…" }. Rindle-User is optional, as on subscribe. Rindle-Stream-Token is the client’s previous stream token, once it has one.

A client needs a stream token before its first subscribe and before it opens its stream, so on page load this call is a round trip before anything else. To avoid it, call stream-auth while server-rendering the page and put the stream token in the HTML.

stream-deauth

POST /db/stream-deauth. Ends every stream for Rindle-User, or for Rindle-Client alone if it is given. Stream tokens issued before the call no longer open or extend a stream.

POST /db/stream-deauth
Authorization: Bearer $RINDLE_API_TOKEN
Rindle-User: user_42

Returns { "ended": n }.

subscribe

POST /db/subscribe. Adds and removes a client’s subscriptions. A client is one browser tab, or other consumer; its results arrive on its stream.

The client and user travel in headers:

Header
Rindle-Client The client’s id.
Rindle-User Optional. Once set, calls for this client with a different user are refused.
Rindle-Stream-Token The client’s latest stream token. Rindle uses it to reach the server that holds the client’s subscriptions.
POST /db/subscribe
Authorization: Bearer $RINDLE_API_TOKEN
Rindle-Client: c_7f3k2q
Rindle-User: user_42
Rindle-Stream-Token: eyJjIjoiY183ZjNrMnEi…
Content-Type: application/json

{
  "ops": [
    { "op": "remove", "id": 17 },
    {
      "op": "add",
      "id": 18,
      "sql": "SELECT * FROM note WHERE folder = ? ORDER BY id DESC",
      "params": [3]
    },
    { "op": "add", "id": 19, "ast": { … }, "mode": "pulse" }
  ]
}

Each subscription has an id the client picks: an integer from 0 to 253 − 1, unique within the client and never reused, even after a remove. An add carries sql and params, or a builder query’s ast, and an optional mode: "flat" (the default) sends rows, "pulse" only that the result changed. A remove carries only the id; removing an id the client doesn’t hold succeeds.

Ops apply in order, each on its own: one refused op doesn’t stop the ones after it, and a batch is not atomic. A remove before an add frees a slot for it.

A client may have several batches in flight at once, and they can reach Rindle in any order. Because ids are never reused, the outcome is the same either way: a remove that arrives before its add is remembered, and the add, when it comes, is ignored with "status": "removed".

The reply comes once every op is accepted or refused, not once its rows are ready; rows arrive on the stream:

{
  "ops": [
    { "id": 17, "status": "ok" },
    { "id": 18, "status": "ok" },
    {
      "id": 19,
      "status": "error",
      "code": "compile",
      "httpStatus": 400,
      "message": "…"
    }
  ]
}
code httpStatus
compile 400 The SQL can’t be kept live. message is the compiler’s.
invalid 400 Any other refusal of the query.
cooling-down 400 This query failed moments ago. Try again later.
too-many-queries 429 The client is at its limit. Remove a subscription first.
shed, not-ready, deferred 503 The server is busy or starting. Retry after retryAfterMs.
internal 500

A malformed op (no id, an unknown op) fails the whole request with 400, naming its index (ops[3]: …). More than 4,096 ops is 413.

A client may hold 256 subscriptions that send rows and 20,000 pulses, and a user 32 clients.

When a Server Goes Away

The server that holds a client’s subscriptions can go away: it restarts, or in a replicated deployment, it’s replaced. Its subscriptions go with it. Rindle then refuses the client’s next subscribe or stream-auth with 409 and "code": "client-lost", and its stream closes.

The client doesn’t replay what failed. It calls stream-auth with no Rindle-Stream-Token, and Rindle places it on a live server. With that new stream token, it sends one batch that adds every subscription it wants now, with the same ids, and opens its stream there. Each subscription starts over with a hello. Ignore replies that arrive late for the old stream token.

transactions

POST /db/transactions. Interactive transactions, for when a statement depends on an earlier one’s result.

Route Body Returns
/db/transactions { "read_only"?: bool, "isolation"?: "serializable" | "snapshot" } { "transaction_id": … }
/db/transactions/{id}/execute { "operation_id": "1", "statements": [ … ] } (statements) { "results": [ … ] }
/db/transactions/{id}/commit { "operation_id": "2" } { "commit_cursor": … }
/db/transactions/{id}/rollback { "operation_id": "2" }
/db/transactions/{id}/cancel { "operation_id": "2" }

operation_id counts up from 1 within the transaction; a repeated id is a retry, and a skipped one is 409 TRANSACTION_OPERATION_SEQUENCE.

Each open transaction uses a private snapshot. Other transactions and independent writes can commit while it remains open. The server validates the transaction at commit, then replays its writes through one committer. Its uncommitted writes do not change live query results.

A conflict returns 409 TRANSACTION_CONFLICT, transaction_state: "closed", and retry_scope: "closure". The server does not repeat the transaction body. The caller decides whether to repeat it from the first statement. A commit with no row changes returns a null commit_cursor and creates no version.

Two limits end a transaction that does not close. An expired transaction rolls back and answers 410 TRANSACTION_CLOSED:

  • sessionDeadlineMs — 5 seconds by default — measures idle time after the last operation finishes. Each operation restarts this limit.
  • sessionMaxMs — 30 seconds by default — measures total time from begin. Operations do not extend this limit.

The server admits at most 1024 open transactions. A full limit returns 503. Schema migrations wait for open transactions. New transactions wait behind a queued migration.

An independent read returns the latest committed state. It does not wait for your transaction or see its uncommitted writes. A read through the transaction sees its own writes.

isolation accepts serializable or snapshot. The default is serializable. A read_only: true transaction defaults to snapshot and refuses writes. A read-only transaction can request serializable explicitly. An authority ignores consistency because it has no upstream replication lag.

Client Route

The one route untrusted clients use; it can be served on its own port.

stream

GET /db/stream, with a stream token. A WebSocket that carries the client’s results.

GET /db/stream?streamToken=<stream token>

The stream token names the client and the user. A browser can’t set headers on a WebSocket, so the stream token travels in the URL, and a page on any origin may connect.

Each message is one JSON frame with an id. The first lists the client’s subscriptions:

{ "id": 1, "t": "client", "queries": [17, 18] }
{ "id": 2, "t": "hello", "queryId": 18, … }
{ "id": 3, "t": "batch", "queryId": 18, "batch": { "events": [ … ] } }
Frame
client The subscriptions Rindle holds for this client.
hello A subscription started. Carries its schema.
batch Row changes for a subscription: adds, removes and edits.
pulse For "pulse" subscriptions: ready lists the ones that just went live, changed the ones whose result a commit changed.
progress Every subscription is current as of this point.
queryError A subscription failed.

A subscription’s first batch holds its whole result and carries engineMs: how long the engine spent producing it. That is the time to build and hydrate the query, if this subscription started it, plus the time to read this subscription’s rows. It leaves out the network and any time the subscription waited in a queue.

When the subscription joined a query that was already running, engineMs is only the read. That first batch also carries hydrateMs: how long the engine took to build and hydrate the query when it first started, for whichever subscription started it. Rindle keeps that number for as long as the query runs.

A write’s changes to every subscription arrive together, as of one transaction. Rindle pings the socket every 15 seconds.

A stream stays open while the client keeps it fresh. Rindle closes it 5 minutes after its last stream token unless the client sends a newer one up the socket:

{ "t": "streamToken", "streamToken": "<fresh stream token>" }

Rindle checks the new stream token as it would to open a stream, then extends the stream by another 5 minutes. A stream token that fails the check closes the stream.

Subscriptions belong to the client, not the stream. If the socket drops, open a new stream with a fresh stream token and after naming the last frame id received (/db/stream?streamToken=…&after=3), and it carries on from there, with nothing missed or repeated. A client with no open stream is kept for 5 seconds.

Stream Tokens

/db/stream-auth issues stream tokens. A stream token opens or extends the client’s stream once, within 30 seconds. It names the client and the user, and in a replicated deployment, the Rindle server that holds the client’s subscriptions, so the stream and the client’s subscribes reach that server. For routing a subscribe, the client’s latest stream token works even after it’s used or expired. Stream tokens are opaque: pass them along as they are.

Rindle refuses a stream token that has expired, was already used, or was issued before a deauth of its user or client. Opening a stream with one is 401.

Health

No auth.

readyz

GET /readyz. 200 when the server is ready, or 503 {"ready": false, "reason": …} while it starts.

version

GET /version. {"service": "rindled", "sha": …}. sha is "unknown" unless the build set RINDLE_GIT_SHA.

stats

GET /stats, with the adminToken if one is set. Counters and gauges for the engine, the subscriptions and the replication position. Set RINDLE_METRICS_ADDR for a Prometheus /metrics listener instead.

Object Storage Retention

For a standalone authority using object storage, these POST routes require adminToken:

Route Body Result
/admin/storage/pin { "name": "release", "version": 42 } Pin a published version. Omit version for the latest published checkpoint.
/admin/storage/unpin { "name": "release" } Remove a pin.
/admin/storage/gc {} Collect expired history and unreachable objects; return retained versions and deletion counts.

These operations run on the background maintenance worker. Invalid or expired versions, and a pin name that is not 1…=128 bytes without control characters, return 400; a full maintenance queue returns 503. A 409 means another writer has taken over this baseKey, so the operation did not apply and this server is stopping. A pin name is trimmed, so "release" and " release " are the same pin. /stats reports pins, the retention floor, and the last collection report or error under storage. See Self-Hosted for retention settings and defaults.