HTTP API
Transport rules, error shape, request ids and the list of endpoints of the Raft DB HTTP JSON API under /v1.
The same port that speaks the binary protocol also speaks HTTP/1.1 and serves the JSON API under /v1. With --studio DIR it also serves the Studio's static files.
Transport#
- Strict HTTP/1.1 with keep-alive. Bodies need
Content-Lengthand are limited to 1 MiB; headers to 16 KiB. Chunked uploads are refused, and there is no HTTP/2, TLS or WebSocket (testbad_http_is_refused_without_hurting_the_server). - JSON bodies are UTF-8. Table and database names are 1 to 64 characters: letters, digits,
_,-. - Large integers: counts and sizes of databases and tables (
rows,documents,indexBytes) are JSON strings ("300"); row documents carry integers as plain JSON numbers, including beyond 2^53, so read them with an exact parser. - Every response has the header
x-rdb-request-id: r_..., and every error body repeats it. collectionsandfieldsin paths are older aliases oftablesandcolumns.
Errors#
Every non-2xx answer has this shape:
{ "error": { "code": "syntax_error", "message": "...", "requestId": "r_..." } }A syntax error in a query also has position: {line, column}. Codes in use: bad_request, syntax_error, unauthenticated, forbidden, not_found, conflict, confirm_required, read_only_replica, constraint_violation, node_not_ready, internal.
| Status | Seen for |
|---|---|
| 400 | bad JSON or body, bad name, bad filter or SQL, bad percent-encoding in a key, confirm_required |
| 401 | no or wrong token, expired session, wrong password |
| 403 | role or database limit does not allow it; read_only_replica on a replica |
| 404 | unknown path, database, table or key |
| 405 | wrong method for a known path (for example GET /v1/query) |
| 409 | name exists, protected table, POST /v1/promote when not applicable |
| 501 | an operation that is not supported on a partitioned table |
| 503 | table is being dropped or renamed |
Endpoints#
| Method and path | Purpose | Page |
|---|---|---|
GET /v1/auth/info | does the server need a login (public) | Authentication |
POST /v1/auth/login, POST /v1/auth/logout, GET /v1/auth/whoami | sessions | Authentication |
GET /v1/server | version, node role, features, replication and sync state | below |
GET /v1/stats | uptime, open connections, per-database counts | below |
GET, POST /v1/databases | list, create | Databases and tables |
DELETE /v1/databases/{db}, POST /v1/databases/{db}/rename | drop, rename | Databases and tables |
GET, POST /v1/databases/{db}/tables | list, create tables | Databases and tables |
GET, DELETE /v1/databases/{db}/tables/{t}; .../rename, .../stats, .../checkpoint, .../indexes | table detail and administration | Databases and tables |
POST .../tables/{t}/documents, GET, DELETE .../documents/{key}, POST .../import | rows | Documents and import |
POST /v1/documents, GET, DELETE /v1/documents/{key} | rows of main.documents | Documents and import |
POST /v1/query | JSON filter or SQL | HTTP: queries |
POST /v1/promote | turn a replica into a primary | Replication |
GET /v1/control/state, POST /v1/control/role, POST /v1/control/throttle | commands from the watcher (control account only) | Replication |
GET /v1/server#
Returns the API version, node role and features. In the test json_endpoints_describe_the_server_and_the_data, api.minor is 2 and node.role is "master". On a replica node.role is replica and a replication object shows the primary, lastSyncSecondsAgo, lastError and per-shard appliedBytes; with synchronous replication a sync object shows replicas, timeoutMs and degradedCommits; with --udp a udp object shows port and counters; passwordChecks counts full password verifications.
GET /v1/stats#
Server-wide: connections (open connections) and databases (one entry per database with table and row counts). Table-level statistics are at GET /v1/databases/{db}/tables/{t}/stats: {shards: [{documents, arenaBytes, garbageBytes}, ...]}, one entry per shard (in the test with 3 shards, the documents values sum to 300).
Cross-origin calls#
Off by default. --cors ORIGIN on the called server answers pre-flights for that origin and adds access-control-allow-origin; it never replaces authentication. --allow-remote-servers on the server that serves the Studio lets its page connect to other servers. * must not be used on an open server.
Not supported yet#
Cursors as a resource, explain, activity list, cluster and backup endpoints, settings and users over HTTP, WebSocket streams, HTTP/2 and TLS appear in the design draft of the API but are not implemented.