KV store

A per-app key/value store backed by SQLite, exposed over the loopback SDK at /__bext/sdk/kv/*. Set, get, list by prefix and delete — with an optional ttl (seconds) for self-expiring rows. Every key here lives under the demo-kv.

Tip
Every store is walled off by the X-Bext-App-Id header: two apps can both use the key session:42 and never collide. Pass a ttl and the row deletes itself — perfect for caches or short-lived tokens.

Set a key

Keys (3)

keyvalue
check-1781135966ok123
counter2
greetinghello world
src/lib/kv-store.tsTypeScript
// KV is a per-app key/value store (SQLite-backed) with optional TTL.
// PRISM pages reach it over the loopback SDK; no admin token needed.
const SDK = "http://127.0.0.1/__bext/sdk";
const APP = "demo-kv";

const h = { "X-Bext-App-Id": APP, "Content-Type": "application/json" };

// set with a 60s TTL — the row self-expires
await fetch(SDK + "/kv/set", { method: "POST", headers: h,
  body: JSON.stringify({ key: "session:42", value: { user: "ada" }, ttl: 60 }) });

// get — value comes back as the JSON text you stored
const { value } = await (await fetch(SDK + "/kv/get", { method: "POST", headers: h,
  body: JSON.stringify({ key: "session:42" }) })).json();

// list keys by prefix, then delete
await fetch(SDK + "/kv/list", { method: "POST", headers: h,
  body: JSON.stringify({ prefix: "session:", limit: 100 }) });
await fetch(SDK + "/kv/delete", { method: "POST", headers: h,
  body: JSON.stringify({ key: "session:42" }) });