Native API

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-Length and are limited to 1 MiB; headers to 16 KiB. Chunked uploads are refused, and there is no HTTP/2, TLS or WebSocket (test bad_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.
  • collections and fields in paths are older aliases of tables and columns.

Errors#

Every non-2xx answer has this shape:

JSON
{ "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.

StatusSeen for
400bad JSON or body, bad name, bad filter or SQL, bad percent-encoding in a key, confirm_required
401no or wrong token, expired session, wrong password
403role or database limit does not allow it; read_only_replica on a replica
404unknown path, database, table or key
405wrong method for a known path (for example GET /v1/query)
409name exists, protected table, POST /v1/promote when not applicable
501an operation that is not supported on a partitioned table
503table is being dropped or renamed

Endpoints#

Method and pathPurposePage
GET /v1/auth/infodoes the server need a login (public)Authentication
POST /v1/auth/login, POST /v1/auth/logout, GET /v1/auth/whoamisessionsAuthentication
GET /v1/serverversion, node role, features, replication and sync statebelow
GET /v1/statsuptime, open connections, per-database countsbelow
GET, POST /v1/databaseslist, createDatabases and tables
DELETE /v1/databases/{db}, POST /v1/databases/{db}/renamedrop, renameDatabases and tables
GET, POST /v1/databases/{db}/tableslist, create tablesDatabases and tables
GET, DELETE /v1/databases/{db}/tables/{t}; .../rename, .../stats, .../checkpoint, .../indexestable detail and administrationDatabases and tables
POST .../tables/{t}/documents, GET, DELETE .../documents/{key}, POST .../importrowsDocuments and import
POST /v1/documents, GET, DELETE /v1/documents/{key}rows of main.documentsDocuments and import
POST /v1/queryJSON filter or SQLHTTP: queries
POST /v1/promoteturn a replica into a primaryReplication
GET /v1/control/state, POST /v1/control/role, POST /v1/control/throttlecommands 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.

See also#

Native interface, Authentication