Skip to content

Bulk read records

POST /v4/storage/{storage}/read

Read one or more records from a namespace. The path parameter storage specifies which namespace to read from.

Request body

FieldTypeDescription
keysarray<string>Optional. List of keys to read. If omitted, the response contains only latest transaction id, no keys will be returned.
txinteger<int64>Optional. Transaction ID to read from. If omitted, reads from the latest transaction.

Response schema

FieldTypeDescription
dataarray<Record>Array of records that were found.
countinteger<int64>Number of records returned.
txinteger<int64>Transaction ID of the read operation.
durationstringTime taken to process the read request, returned in a human-readable format (e.g., "1.234567ms").

Record object

FieldTypeDescription
keystringThe key that was read
valueanyThe value associated with the key. Will be null if key has no value.
txinteger<int64>Transaction ID when this record was last modified
binarybooleanWhether the value is binary data

Example

sh
curl --location 'https://api.litebase.io/v4/storage/sample/read' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $LITEBASE_API_KEY" \
--data '{
    "keys": ["city:1", "city:2"]
}'

Response:

json
HTTP/1.1 200 OK
Content-Type: application/json

{
    "data": [
        {
            "key": "city:1",
            "value": {
                "name": "Braavos"
            },
            "tx": 1,
            "binary": false
        },
        {
            "key": "city:2",
            "value": {
                "name": "Oldtown"
            },
            "tx": 1,
            "binary": false
        }
    ],
    "count": 2,
    "tx": 1,
    "duration": "1.234567ms"
}

Read from specific transaction

sh
curl --location 'https://api.litebase.io/sample/storage/read' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $LITEBASE_API_KEY" \
--data '{
    "keys": ["city:1"],
    "tx": 1
}'

Response:

json
HTTP/1.1 200 OK
Content-Type: application/json

{
    "data": [
        {
            "key": "city:1",
            "value": {
                "name": "Braavos"
            },
            "tx": 1
        }
    ],
    "tx": 1,
    "duration": "0.987654ms"
}

Read when key having value cleared

Reading a key with value cleared will return key and transaction id only.

sh
curl --location 'https://api.litebase.io/sample/storage/read' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $LITEBASE_API_KEY" \
--data '{
    "keys": ["city:1"]
}'

Response:

json
HTTP/1.1 200 OK
Content-Type: application/json

{
    "data": [
        {
            "key": "city:1",
            "tx": 2
        }
    ],
    "tx": 2,
    "duration": "0.987654ms"
}