Skip to content

HTTP API by example

Every example on this page runs in CI (tools/docs-snippets.py, group http) against a server built from this repository, in order. They use two variables: OLIVIADB_URL (the server, e.g. https://localhost:8443; for the image's self-signed certificate, docker cp oliviadb:/data/tls/server.pem oliviadb-ca.pem and export CURL_CA_BUNDLE=$PWD/oliviadb-ca.pem) and OLIVIADB_KEY (an API key, e.g. docker exec oliviadb cat /data/api-key). The reference for each route is the network API.

The schema

Native aggregates come from a schema given to the server ("schema" in its configuration, or OLIVIADB_SCHEMA in the image). The examples use this one: a shelf of books with a log of notes, and an access profile for the service the key belongs to.

schema shelf version 1

aggregate Shelf {
  key id: string(16)
  1 label: string(40)
  2 count: int32

  child Book [isbn: string(13)] unique {
    1 title: string(80)
    2 price: decimal(9,2)
  }

  child Log ordered { 1 note: text }
}

index book_by_isbn on Shelf/Book(isbn) unique

profile app for service "app" {
  consistency strong, as_of allowed

  get    Shelf/{id}/**
  list   Shelf limit 100
  list   Shelf/{id}/Book
  list   Shelf/{id}/Log
  insert Shelf
  insert Shelf/{id}/Book
  insert Shelf/{id}/Log
  update Shelf/{id}           fields(label, count)
  update Shelf/{id}/Book/{n}  fields(price)
  delete Shelf/{id}
  delete Shelf/{id}/Book/{n}
  lookup book_by_isbn -> Shelf
  search Shelf by text budget 2000 tokens
}

Create

curl -fsS -X POST "$OLIVIADB_URL/v1/aggregates/Shelf/s1" \
  -H "Authorization: Token $OLIVIADB_KEY" -H 'content-type: application/json' \
  -d '{"fields": {"label": "Kitchen", "count": 2}}'
curl -fsS -X POST "$OLIVIADB_URL/v1/aggregates/Shelf/s1/Book/9780000000017" \
  -H "Authorization: Token $OLIVIADB_KEY" -H 'content-type: application/json' \
  -d '{"fields": {"title": "Bread", "price": "12.50"}}'
curl -fsS -X POST "$OLIVIADB_URL/v1/aggregates/Shelf/s1/Log" \
  -H "Authorization: Token $OLIVIADB_KEY" -H 'content-type: application/json' \
  -d '{"fields": {"note": "first shelf"}}'

Read a node, a tree, a listing

curl -fsS "$OLIVIADB_URL/v1/aggregates/Shelf/s1" -H "Authorization: Token $OLIVIADB_KEY"
curl -fsS "$OLIVIADB_URL/v1/aggregates/Shelf/s1?tree=true" -H "Authorization: Token $OLIVIADB_KEY"
curl -fsS "$OLIVIADB_URL/v1/aggregates/Shelf/s1/Book?limit=10" -H "Authorization: Token $OLIVIADB_KEY"
curl -fsS -X PATCH "$OLIVIADB_URL/v1/aggregates/Shelf/s1/Book/9780000000017" \
  -H "Authorization: Token $OLIVIADB_KEY" -H 'content-type: application/json' \
  -d '{"fields": {"price": "11.00"}}'
curl -fsS "$OLIVIADB_URL/v1/lookup/book_by_isbn?key=9780000000017" -H "Authorization: Token $OLIVIADB_KEY"
curl -fsS -X POST "$OLIVIADB_URL/v1/search/Shelf" \
  -H "Authorization: Token $OLIVIADB_KEY" -H 'content-type: application/json' \
  -d '{"query": "bread", "budget": 500}'

Several writes as one transaction

curl -fsS -X POST "$OLIVIADB_URL/v1/txn" \
  -H "Authorization: Token $OLIVIADB_KEY" -H 'content-type: application/json' \
  -d '{"ops": [
        {"op": "update", "path": "Shelf/s1", "fields": {"count": 3}},
        {"op": "insert", "path": "Shelf/s1/Book/9780000000024", "fields": {"title": "Soup", "price": "8.00"}}
      ]}'

Agent memory

curl -fsS -X POST "$OLIVIADB_URL/v1/memory/remember" \
  -H "Authorization: Token $OLIVIADB_KEY" -H 'content-type: application/json' \
  -d '{"thread": "t1", "text": "Ann works at Acme.", "step_id": "t1-1", "entities": ["Ann"],
       "facts": [{"entity": "Ann", "attr": "employer", "value": "Acme"}]}'
curl -fsS -X POST "$OLIVIADB_URL/v1/memory/recall" \
  -H "Authorization: Token $OLIVIADB_KEY" -H 'content-type: application/json' \
  -d '{"query": "Where does Ann work?", "budget": 300}'

DL/I databases

A server with a dli section serves DL/I databases read only (the network API, "DL/I databases"). Here it serves the parts database of the DL/I quickstart after its C example ran (the two parts it inserted, written in ASCII with little-endian binary), under this view PSB for the caller's principal (CI: group dli-http, a server with "dli": {"store": "db-c", "library": "lib", "runtime": "ascii-le", "views": {"app": "view.psb"}}):

         PCB   TYPE=DB,DBDNAME=PARTDB,PROCOPT=G,KEYLEN=10
         SENSEG NAME=PART,PARENT=0
         SENSEG NAME=STOCK,PARENT=PART
         PSBGEN LANG=COBOL,PSBNAME=PARTVIEW
         ROWS  DBDNAME=PARTDB,ALL=YES
         END

A segment by its sequence field, the same with its subtree, a listing in pages:

curl -fsS -w '\n' "$OLIVIADB_URL/v1/dli/PARTDB/PART/P00011" -H "Authorization: Token $OLIVIADB_KEY"
curl -fsS -w '\n' "$OLIVIADB_URL/v1/dli/PARTDB/PART/P00010?tree=true" -H "Authorization: Token $OLIVIADB_KEY"
curl -fsS -w '\n' "$OLIVIADB_URL/v1/dli/PARTDB/PART?limit=1" -H "Authorization: Token $OLIVIADB_KEY"
curl -fsS -w '\n' "$OLIVIADB_URL/v1/dli/PARTDB/PART?limit=1&after=P00010" -H "Authorization: Token $OLIVIADB_KEY"

prints (each answer also has version, the version it was read at, and each segment its layout, the SHA-256 of its field layout):

{"path": "PARTDB/PART/P00011", "type": "PART", "key": {"PARTNO": "P00011"}, "fields": {"PARTNO": "P00011", "DESC": "SPRING"}}
{"path": "PARTDB/PART/P00010", "type": "PART", "key": {"PARTNO": "P00010"}, "fields": {"PARTNO": "P00010", "DESC": "WASHER"}, "children": {"STOCK": []}}
{"nodes": [{"path": "PARTDB/PART/P00010", "type": "PART", "key": {"PARTNO": "P00010"}, "fields": {"PARTNO": "P00010", "DESC": "WASHER"}}], "next": "P00010"}
{"nodes": [{"path": "PARTDB/PART/P00011", "type": "PART", "key": {"PARTNO": "P00011"}, "fields": {"PARTNO": "P00011", "DESC": "SPRING"}}], "next": null}

The native protocol answers the same reads as rows (route 0x07 DLI); the clients decode them as they decode aggregate rows.