Native API

The native interface

What the native (non-SQL) interface of Raft DB consists of and which page describes which part.

Raft DB stores JSON-like documents under a key. SQL is one way in (see the SQL reference); the native interface is the other, and the SQL front-ends are built on it. It has two doors on one TCP port (default 127.0.0.1:7480):

DoorForFormatPage
Binary wire protocolapplications and connectors; the fast pathlength-prefixed frames, documents in their stored binary form or as JSON textWire protocol
HTTP JSON API (/v1/...)administration, the Studio, scripts, curlHTTP/1.1 with JSON bodiesHTTP API

The server tells them apart by the first bytes of a connection: the fourth byte of a binary frame is 0 or 1 (a frame is at most 16 MiB), HTTP text is far above that.

What a request can do#

Both doors reach the same engine, so the same operations exist in both:

  • write a document by key (Put, Insert, Delete, or POST /v1/documents);
  • read a document by key (Get, or GET /v1/documents/{key});
  • select documents with a JSON filter or a SQL SELECT, as a count or as pages with a cursor (Filter language);
  • create secondary indexes, databases and tables.

SQL and JSON filters are compiled to the same plan (Plan IR) and run by the same executor, with the same strict typing rules and the same indexes.

Pages of this chapter#

  1. Wire protocol: frame layout and every message.
  2. Connections, errors and versions: handshake, Use, error codes, protocol version 2 and streams.
  3. Pipelining and batching: many requests in flight, out-of-order replies, deferred writes.
  4. HTTP API: transport rules, error shape, endpoint list.
  5. HTTP: databases and tables
  6. HTTP: documents and import
  7. HTTP: queries
  8. Authentication: shared token, accounts, session tokens, roles.
  9. Filter language
  10. Plan IR
  11. Documents and schemas: the stored format and type checking.

Rust client#

raftdb-client is the reference client of the binary protocol: a blocking client with one-shot calls (connect, use_table, put_json, get_json, delete, count, filter_page, sql_page, create_index, scan) and low-level send / flush / recv for pipelining. Connectors for other languages follow the same protocol; see Connectors.

Not supported yet#

  • TLS on either door: credentials and documents cross the network in clear text, so use loopback or a trusted network.
  • WebSocket, HTTP/2, chunked HTTP uploads.
  • Wire requests GetBatch and Cancel are defined in the codec but the server answers NOT_SUPPORTED.
  • Compression of frames.