@askdb/http-api
v1.0.0-beta.42
Published
AskDB HTTP API: minimal HTTP wrapper around @askdb/core. POST /ask returns validated SQL only.
Maintainers
Readme
@askdb/http-api
Minimal HTTP surface that wraps @askdb/core — no duplicated NL→SQL logic. POST /ask returns validated SQL only.
Status: pre-1.0.
Install
pnpm add -g @askdb/http-api
askdb-httpOr run from a clone — see "Local run" below.
Local run
From repo root:
pnpm -C apps/http-api build
node apps/http-api/dist/bin.jsDev watch (runs with apps/http-api as the working directory):
pnpm -C apps/http-api dev:watchSet ASKDB_SCHEMA_PATH in the repo-root .env (recommended). The binary also loads askdb.config.* / .config/askdb.* from the current working directory via @askdb/config after resolving .env candidates (repo root, cwd, package dir).
# in ../../.env (repo root):
# ASKDB_SCHEMA_PATH=fixtures/schemas/orders-users.schema.jsonHealth check:
curl -sS http://127.0.0.1:3000/healthAsk (curl)
curl -sS http://127.0.0.1:3000/ask \
-H 'content-type: application/json' \
-H 'x-correlation-id: demo-123' \
-d "$(cat <<'JSON'
{
"question": "How many users are there?"
}
JSON
)"Notes:
- Correlation: if you omit
x-correlation-id, the server generates one and returns it. - Mode: optional
x-askdb-modeheader (bodymodewins if present). - Execution: not supported. Retired execution controls return
400; review generated SQL and run any approved query outside AskDB under your own database roles, read-only controls, tenant policy, and audit logging. - Generation config: set
OPENAI_API_KEY(or for tests/dev, setASKDB_MOCK_SQLto bypass live model calls). - Schema config (recommended): set
ASKDB_SCHEMA_PATHto an AskDB Schema v2 directory, bundled JSON file, orschema.json. You can also sendschemaJsonper request as an override, but it doesn’t scale.
Ask (Node)
const res = await fetch("http://127.0.0.1:3000/ask", {
method: "POST",
headers: {
"content-type": "application/json",
"x-correlation-id": "demo-123",
"x-askdb-mode": "schema_only",
},
body: JSON.stringify({
question: "How many users are there?",
}),
});
console.log(await res.json());