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:
https://api.litebase.iohttps://api.litebase.ioAuthentication
Include this key in the Authentication header:
https://api.litebase.io
Authorization: Bearer LITEBASE_API_KEYhttps://api.litebase.io
Authorization: Bearer LITEBASE_API_KEYor using api_key as query params:
https://api.litebase.io?api_key=LITEBASE_API_KEYhttps://api.litebase.io?api_key=LITEBASE_API_KEYReplace LITEBASE_API_KEY with your actual API key.
Endpoints
The LiteTx API has the following endpoints:
POST /tx- Commit transactionGET /tx- List transactionsGET /tx/:id- Get transaction by idGET /versions- Get key versions
Commit transaction
POST /txPOST /txCommit a new transaction to the distributed log.
Examples
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 */ }
}'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:
{
"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.
GET /tx?max_tx=:id&limit=:limitGET /tx?max_tx=:id&limit=:limitResponse
[
{
"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.
GET /tx/:idGET /tx/:idResponse
{
"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.
GET /versions?tx=:id&keys=key1,key2GET /versions?tx=:id&keys=key1,key2Response
{
"tx": 1,
"data": {
"key1": 1,
"key2": 2
},
"duration": "5ms"
}{
"tx": 1,
"data": {
"key1": 1,
"key2": 2
},
"duration": "5ms"
}POST /versions
{
"tx": 1,
"keys": ["key1", "key2"]
}POST /versions
{
"tx": 1,
"keys": ["key1", "key2"]
}