Skip to content

HTTP API

The surface endpoint serves these routes under the prefix the consumer mounts it at; every path here is relative to that prefix. Bodies and answers are JSON. null and an absent field read the same. Times are ISO-8601 in UTC.

Records

Anchor    { kind: string, id: string }
Pending   { kind: string, fields: { [name: string]: string } }
RailEntry { text: string, shape: string, anchor: Anchor | null, modifiers: { [key: string]: string },
            at: string, utterance?: string }
Showing   { device: string, deviceClass: string, room: boolean, since: string }
Surface   { id: string, owner: string, opened: boolean, shape: string, anchor: Anchor | null,
            modifiers: { [key: string]: string }, pending: Pending | null,
            rail: RailEntry[], showing: Showing[], version: number }
Focus     { id: string, device: string, fields: { [key: string]: string }, at: string, version: number }
  • version rises by one on every change the surface records and never falls.
  • rail is newest first, at most the vocabulary's railLength long. utterance is absent on an entry whose request named none.
  • opened is false only for a surface nobody opened, which no route returns: they answer 404 or 409 instead.
  • Focus has a version of its own. Never set, it is {"device":"","fields":{},"at":"1970-01-01T00:00:00Z","version":0}.

Bodies

Open      { owner: string, shape?: string }
Move      { shape?: string, anchor?: Anchor, clearAnchor?: boolean,
            modifiers?: { [key: string]: string }, clearModifiers?: string[],
            pending?: Pending, clearPending?: boolean, request?: string, utterance?: string }
Say       { text: string, utterance?: string }
Show      { device: string, deviceClass: string, room?: boolean }
Hide      { device: string }
SetFocus  { device: string, fields: { [key: string]: string } }
Said      { understood: boolean, reason: string | null, surface: Surface }
Heard     { understood: boolean, reason: string | null, move: Move | null }

A Move is applied in this order: the shape; the anchor, clearAnchor winning over anchor; each clearModifiers key removed, then each modifiers entry set; the pending, clearPending winning over pending; then the request put on the rail with the surface as it then stands. The surface and its moves explains the order.

Routes

Route Body Answers
GET /{id} 200 Surface
GET /{id}/stream 200 text/event-stream, the stream
GET /?owner=<owner> 200 Surface[], the owner's opened surfaces, read from the view
POST /{id}/open Open 200 Surface at version 1
POST /{id}/moves Move 200 Surface
POST /{id}/say Say 200 Said
POST /{id}/hear Say 200 Heard, nothing persisted
POST /{id}/show Show 200 Surface
POST /{id}/hide Hide 200 Surface; unchanged when the device was not showing
DELETE /{id} 204, the surface closed and its id free
GET /{id}/focus 200 Focus
PUT /{id}/focus SetFocus 200 Focus
GET /{id}/focus/stream 200 text/event-stream of Focus rows

The three focus routes exist only when the consumer registers the focus lane.

Refusals

A refusal is {"status": <code>, "error": <sentence>}. The sentence names what was refused, such as the word the vocabulary lacks, and is for a person; match on the status.

Route Status When error
GET /{id}, GET /{id}/stream 404 never opened surface is not opened
GET / 400 no owner query parameter 'owner' is required
POST /{id}/open 409 already opened surface is already opened
400 a blank owner an owner is needed to open a surface
400 a shape the vocabulary lacks the vocabulary has no shape '<shape>'
POST /{id}/moves 409 not opened surface is not opened
400 a move naming nothing a move names nothing
400 a shape, anchor kind, modifier key or pending kind the vocabulary lacks the vocabulary has no <part> '<word>'
POST /{id}/say 404 not opened surface is not opened
400 blank text nothing was said
400 the interpreter's move uses a word the vocabulary lacks the vocabulary has no <part> '<word>'
POST /{id}/hear 404 not opened surface is not opened
400 blank text nothing was said
POST /{id}/show 409 not opened surface is not opened
400 a blank device a device needs a name
400 a device class the vocabulary lacks the vocabulary has no device class '<class>'
POST /{id}/hide 409 not opened surface is not opened
DELETE /{id} 409 not opened surface is not opened
focus routes 404 the surface never opened surface is not opened
PUT /{id}/focus 400 a blank device a device needs a name
400 a focus key the vocabulary lacks the vocabulary has no focus key '<key>'

Words that are not understood are not a refusal: say and hear answer 200 with understood false and the interpreter's reason.

The stream

GET /{id}/stream serves server-sent events, as ankka serves a watched view row:

Event Data When
row {"key": id, "row": Surface} the surface now, then every version written while the stream is open; coalesced, never an older version after a newer, possibly fewer than were written, and the same version possibly twice
caught-up {} once, after the first row
removed {"key": id} the surface was closed
ended {"reason": string} the server ended the stream: rebuilt, instance-stopping, listener-lost or unread

An event's event: and data: lines may come in either order; read an event up to its blank line. A device that reconnects for any reason fetches GET /{id} first and then streams again, so a change made while it was away is never missed.

GET /{id}/focus/stream is the same, with Focus rows.

What a device does

A device speaking this API by hand, without the device package, keeps these rules:

  • It holds one surface and its version, and takes a surface from an answer or the stream only when its version is higher than the one held.
  • It may apply its own move locally by the fold before the answer comes, and replaces the result with the answer. It never applies a say locally.
  • It calls show after connecting and hide before leaving.
  • It holds the answer to its newest say only.
  • With the focus lane, it streams the focus beside the surface, takes a streamed focus only at a higher version, and sends its own at most once per interval with the last value in a window always sent.