HTTP administration API
The administration endpoints of raftdb-server on its HTTP port: login, server and statistics, databases and tables, checkpoint, promote and the control interface, with roles and error rules.
raftdb-server serves HTTP on the same port as its binary protocol (the first bytes of a connection tell them apart). The JSON API is what the Studio uses and is the way to administer a server that has no SQL front-end. The full data API (documents, queries, import) is described in the native API chapter; this page covers administration.
The HTTP server is strict and small: HTTP/1.1 with keep-alive, bodies up to 1 MiB with Content-Length, headers up to 16 KiB; no chunked uploads, no HTTP/2, no WebSocket. The main port is plain HTTP; for TLS set https-addr (a second port with the same API, see TLS and encryption).
Syntax#
POST /v1/auth/login {"user": "NAME", "password": "PASSWORD"} -> a session token (8 hours)
Authorization: Bearer <token> on every other requestThe token is also accepted directly as a Bearer value when the server runs with token = SECRET. A server in open mode needs no login. A request without a valid login is 401 unauthenticated. A failed login is answered after 250 ms.
Endpoints#
| Method and path | Role | What it does |
|---|---|---|
POST /v1/auth/login | none | Log in. |
GET /v1/auth/whoami | any | The account's grants: [{role, database}]. |
POST /v1/auth/logout | any | End the session token. |
GET /v1/server | any | API version, server version, node.role (master or replica), uptime, features, replication and per-group replication status, forwarding counters, sync (replicas, timeout, degraded commits), passwordChecks (full hash checks run), UDP status. |
GET /v1/stats | any | Uptime, connections and, per visible database, table count and row count. |
GET /v1/databases | any | The databases the account may see. |
POST /v1/databases | admin (unscoped) | {"name": "..."}: create a database (201). |
DELETE /v1/databases/{db} | admin | Drop a database. The body must repeat the exact name: {"confirm": "<name>"}, otherwise 400 confirm_required and nothing happens. |
POST /v1/databases/{db}/rename | admin | {"name": "new"}. |
GET /v1/databases/{db}/tables | any | List tables. |
POST /v1/databases/{db}/tables | admin | Create a table. partitions in the body makes a partitioned table. |
DELETE /v1/databases/{db}/tables/{t} | admin | Drop a table; the body must confirm the name. |
POST /v1/databases/{db}/tables/{t}/rename | admin | {"name": "new"}. |
POST /v1/databases/{db}/tables/{t}/checkpoint | admin | Rewrite the shard logs; the table is unavailable meanwhile. |
GET /v1/databases/{db}/tables/{t}/stats | any | Row counts, indexes with entries and bytes, sizes. |
POST /v1/databases/{db}/tables/{t}/documents/indexes | readwrite | Create a secondary index. |
POST /v1/query | any | Run a JSON filter or SQL (language: "sql"). |
POST /v1/promote | admin | On a replica: stop replication and allow writes. |
GET /v1/control/state, POST /v1/control/role, POST /v1/control/throttle | control | The control interface used by the watcher. |
(collections is accepted as another word for tables in the paths.)
Roles#
| Role | Can |
|---|---|
readonly | Queries, GETs, listings. |
readwrite | Also write, delete, import, create indexes. |
admin | Also create, drop, rename and checkpoint databases and tables. |
control | Only the /v1/control interface. It can do nothing with data. |
An account written NAME:PASSWORD:ROLE@DATABASE is limited to that database: other databases vanish from the listings, direct access is 403 forbidden, and it cannot create databases. The shared token and an open server are administrators everywhere.
Remarks#
- A replica refuses writes with
403 read_only_replica(binary error code 12READ_ONLY). Logins, queries,POST /v1/promoteand/v1/controlstill work. - With table groups, a request for a table whose primary is another node answers
409 not_leaderwith the primary's address; the binary protocol forwards instead. mainandmain.documentscannot be dropped or renamed (409).- A name that already exists is
409; an invalid name is400. Names are 1 to 64 characters of letters, digits,_and-. - A partitioned table answers
501to operations that are not built for it yet (rename and import have special handling; see D50 layer 2). - The SQL front-end's databases and tables are Raft DB databases and tables too, with encoded names for unusual characters and hidden
__tables: do not administer those through this API.
Examples#
Log in, then list the databases:
curl -s -X POST http://127.0.0.1:7480/v1/auth/login -d '{"user":"admin","password":"..."}'
curl -s http://127.0.0.1:7480/v1/databases -H "Authorization: Bearer TOKEN"Checkpoint a table (the table is unavailable meanwhile):
curl -s -X POST http://127.0.0.1:7480/v1/databases/main/tables/documents/checkpoint -H "Authorization: Bearer TOKEN"Drop a table (the name is repeated as confirmation):
curl -s -X DELETE http://127.0.0.1:7480/v1/databases/shop/tables/old -H "Authorization: Bearer TOKEN" -d '{"confirm":"old"}'