HTTP protocol: negotiation and SQL execution
Contracts 2/3/4, authentication, typed parameters, result sequences and cursor release.
Session contract and consumption state machine
The result protocol is negotiated independently of the distribution number and /api/v1 route namespace. A typed execution associates a query_id, metadata and a sequence of packets. Consumers distinguish waiting, data packets, result-set completion and global completion. This separation preserves export correctness, bounded fetch replay and procedure output delivery.
Discover capabilities and select a contract
GET /api/capabilities and /api/v1/capabilities are public. The response advertises protocol_versions:[2,3,4] and latest_protocol_version:4. Flat fields, including protocol_version:3 and multiple_results:false, describe protocol 3; advanced capabilities are in protocol_4. Without explicit selection an ordinary query stays on legacy protocol 2. Description defaults to 3. Infer neither protocol from 0.2.83 nor from /v1.
Protocol 3 accepts one SELECT or DML statement with typed metadata. Protocol 4 adds DDL, scripts, procedures, outputs and multiple result sets while retaining permission checks. No protocol adds multi-statement transactions.
Authentication and route table
| Operation | Account / cookie | Bearer key |
|---|---|---|
| Discovery GET | /api/capabilities | /api/v1/capabilities |
| Login POST | /api/login | No login; Authorization: Bearer … |
| SQL or description POST | /api/query | /api/v1/query |
| Next batch POST | /api/fetch | /api/v1/fetch |
| Cancel POST | /api/cancel | /api/v1/cancel |
| Close POST | /api/close | /api/v1/close |
| Logout POST | /api/logout | Administrator revocation |
Login receives { "login": "my_account", "password": "externally-supplied-secret" } and returns HttpOnly cookie octaviius_session. POST bodies are UTF-8 JSON. The Studio, driver and Python example use compatibility header X-Octaviius-Client: Studio, including behind a reverse proxy. It replaces neither authentication nor authorization; Origin/Host checks still apply.
Send a typed query
Send this body to the query route for your identity. params carries values, parameter_types declares their types and SQL placeholders are named, such as @pays. Never concatenate user values into SQL. Parameters cannot replace table or column names. Type NULL parameters with params:{"pays":null}.
timeout is in seconds; 0 imposes no SQL deadline through this field. The HTTP client timeout is separate and must allow a server response. query_id correlates/cancels an operation; it is not a durable write-deduplication key. Send database names separately; dbo is the default schema.
{
"protocol_version": 3,
"database": "Atelier",
"query_id": "lecture-001",
"sql": "SELECT Id, Montant FROM dbo.Ventes WHERE Pays = @pays ORDER BY Id",
"params": {"pays": "France"},
"parameter_types": {"pays": {"type": "NVARCHAR", "args": [40]}},
"batch_rows": 8192,
"batch_bytes": 1048576,
"timeout": 60
}Read responses and subsequent batches
A data packet includes columns, columns_meta, rows, sequence, query_id, complete and usually a cursor. The first batch may be empty. pending:true means waiting, not an empty result or completion, and consumes no sequence. After normal sequence n, request n+1. For pending, request next_sequence without incrementing. Waiting packets may have empty metadata.
Requesting the last sequence replays the retained packet; the next sequence implicitly acknowledges it. Skipped or older sequences are rejected. Continue until complete:true, even after a full-sized batch. The last packet may be empty. Explicitly close the cursor after completion: terminal packets are retained for replay.
{"protocol_version":3,"cursor":"TOKEN_RECU","sequence":1}Describe a SELECT without execution
Add describe_only:true to query. The response contains description_only:true, column metadata, rows:[] and complete:true, without a cursor. Objects and permissions are checked and catalog metadata read; data are not scanned and expressions not evaluated. Only describable SELECTs are accepted: a write command with describe_only is rejected rather than executed.
{"protocol_version":3,"database":"Atelier","describe_only":true,
"sql":"SELECT CAST(@n AS DECIMAL(19,4)) AS montant",
"params":{"n":null},"parameter_types":{"n":{"type":"DECIMAL","args":[19,4]}}}Cancel, close and interpret errors
Cancel receives { "protocol_version":3, "query_id":"lecture-001" }. Close receives { "protocol_version":3, "cursor":"RECEIVED_TOKEN" }. Use the same session or key. Cancellation may leave produced packets and is not rollback. Close stops remaining production and releases the cursor. Early closure of a script does not ensure later statements execute.
Errors retain error and add diagnostic, request_id, query_id and core_version. Diagnostics include a stable code, SQLSTATE and message; protocol 4 also includes native_code. X-Request-ID and X-Octaviius-Core-Version headers help debugging. See cursors and errors.