Skip to content

Overview

This reference guide is designed to give you all the information you need to start integrating LiteTx into your data apps.

Base URL

All API endpoints are relative to the base URL:

bash
https://api.litebase.io
https://api.litebase.io

Authentication

Include this key in the Authentication header:

bash
https://api.litebase.io
Authorization: Bearer LITEBASE_API_KEY
https://api.litebase.io
Authorization: Bearer LITEBASE_API_KEY

or using api_key as query params:

bash
https://api.litebase.io?api_key=LITEBASE_API_KEY
https://api.litebase.io?api_key=LITEBASE_API_KEY

Replace LITEBASE_API_KEY with your actual API key.

Endpoints

The LiteTx API has the following endpoints:

  • POST /tx - Commit transaction
  • GET /tx - List transactions
  • GET /tx/:id - Get transaction by id
  • GET /versions - Get key versions

Commit transaction

bash
POST /tx
POST /tx

Commit a new transaction to the distributed log.

Examples

bash
curl -X POST https://api.litebase.io/tx \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer {LITEBASE_API_KEY}" \
  -d '{
  "read_set": {"key1":1, "key2": 2, ...},
  "write_set": ["key1", "key_2", ...],
  "data": { /* Any data */ }
}'
curl -X POST https://api.litebase.io/tx \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer {LITEBASE_API_KEY}" \
  -d '{
  "read_set": {"key1":1, "key2": 2, ...},
  "write_set": ["key1", "key_2", ...],
  "data": { /* Any data */ }
}'
typescript
const resp = await fetch('https://api.litebase.io/tx', {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
        'Authorization': `Bearer ${LITEBASE_API_KEY}`
    },
    body: JSON.stringify({
        read_set: { key1: 1, key2: 2 /*, ...*/ },
        write_set: ["key1", "key_2" /*, ...*/],
        data: { /* Any data */ }
    })
})
const data = await resp.json()
const resp = await fetch('https://api.litebase.io/tx', {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
        'Authorization': `Bearer ${LITEBASE_API_KEY}`
    },
    body: JSON.stringify({
        read_set: { key1: 1, key2: 2 /*, ...*/ },
        write_set: ["key1", "key_2" /*, ...*/],
        data: { /* Any data */ }
    })
})
const data = await resp.json()

Request Payload

The request payload includes three components:

  • read_set- Key-version pairs to check.
  • write_set - An array of keys that their versions will be updated.
  • data - Any additional data.

Response

Upon successfully committing a transaction, you will get the following response:

json
{
  "tx": 1, 
  "duration": "120ns"
}
{
  "tx": 1, 
  "duration": "120ns"
}

The response object comprises two fields:

  • tx - the transaction id that was just committed.
  • duration - how long it took for the transaction to be processed and committed.

List transactions

Retrieve a list of recent transactions.

bash
GET /tx?max_tx=:id&limit=:limit
GET /tx?max_tx=:id&limit=:limit

Response

json
[
  {
    "tx": 2,
    "read_set": {"key1":1, "key2": 2, ...},
    "write_set": ["key1", "key_2", ...],
    "data": { /* Any data */ }
  },
  {
    "tx": 1,
    "read_set": {"key1":1, "key2": 2, ...},
    "write_set": ["key1", "key_2", ...],
    "data": { /* Any data */ }
  }
]
[
  {
    "tx": 2,
    "read_set": {"key1":1, "key2": 2, ...},
    "write_set": ["key1", "key_2", ...],
    "data": { /* Any data */ }
  },
  {
    "tx": 1,
    "read_set": {"key1":1, "key2": 2, ...},
    "write_set": ["key1", "key_2", ...],
    "data": { /* Any data */ }
  }
]

Get transaction by id

Retrieve details of a specific transaction by its ID.

bash
GET /tx/:id
GET /tx/:id

Response

json
{
  "tx": 1,
  "read_set": {"key1":1, "key2": 2, ...},
  "write_set": ["key1", "key_2", ...],
  "data": { /* Any data */ }
}
{
  "tx": 1,
  "read_set": {"key1":1, "key2": 2, ...},
  "write_set": ["key1", "key_2", ...],
  "data": { /* Any data */ }
}

Get key versions

Retrieve list of key-version pairs up to transaction ID.

bash
GET /versions?tx=:id&keys=key1,key2
GET /versions?tx=:id&keys=key1,key2

Response

json
{
  "tx": 1,
  "data": {
    "key1": 1,
    "key2": 2
  },
  "duration": "5ms"
}
{
  "tx": 1,
  "data": {
    "key1": 1,
    "key2": 2
  },
  "duration": "5ms"
}
bash
POST /versions 
{
  "tx": 1,
  "keys": ["key1", "key2"]
}
POST /versions 
{
  "tx": 1,
  "keys": ["key1", "key2"]
}