Administration

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 request

The 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 pathRoleWhat it does
POST /v1/auth/loginnoneLog in.
GET /v1/auth/whoamianyThe account's grants: [{role, database}].
POST /v1/auth/logoutanyEnd the session token.
GET /v1/serveranyAPI 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/statsanyUptime, connections and, per visible database, table count and row count.
GET /v1/databasesanyThe databases the account may see.
POST /v1/databasesadmin (unscoped){"name": "..."}: create a database (201).
DELETE /v1/databases/{db}adminDrop a database. The body must repeat the exact name: {"confirm": "<name>"}, otherwise 400 confirm_required and nothing happens.
POST /v1/databases/{db}/renameadmin{"name": "new"}.
GET /v1/databases/{db}/tablesanyList tables.
POST /v1/databases/{db}/tablesadminCreate a table. partitions in the body makes a partitioned table.
DELETE /v1/databases/{db}/tables/{t}adminDrop a table; the body must confirm the name.
POST /v1/databases/{db}/tables/{t}/renameadmin{"name": "new"}.
POST /v1/databases/{db}/tables/{t}/checkpointadminRewrite the shard logs; the table is unavailable meanwhile.
GET /v1/databases/{db}/tables/{t}/statsanyRow counts, indexes with entries and bytes, sizes.
POST /v1/databases/{db}/tables/{t}/documents/indexesreadwriteCreate a secondary index.
POST /v1/queryanyRun a JSON filter or SQL (language: "sql").
POST /v1/promoteadminOn a replica: stop replication and allow writes.
GET /v1/control/state, POST /v1/control/role, POST /v1/control/throttlecontrolThe control interface used by the watcher.

(collections is accepted as another word for tables in the paths.)

Roles#

RoleCan
readonlyQueries, GETs, listings.
readwriteAlso write, delete, import, create indexes.
adminAlso create, drop, rename and checkpoint databases and tables.
controlOnly 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 12 READ_ONLY). Logins, queries, POST /v1/promote and /v1/control still work.
  • With table groups, a request for a table whose primary is another node answers 409 not_leader with the primary's address; the binary protocol forwards instead.
  • main and main.documents cannot be dropped or renamed (409).
  • A name that already exists is 409; an invalid name is 400. Names are 1 to 64 characters of letters, digits, _ and -.
  • A partitioned table answers 501 to 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"}'

See also#