Docs REST API

REST API Reference

HTTP API on port 5020 powered by Axum — RESTful endpoints for all 5 data types

SoliKV exposes two interfaces: the Redis protocol on port 6379 for RESP2 operations, and this REST API on port 5020 for HTTP access to all data types. Both share the same engine — AOF persistence covers both interfaces automatically.

Authentication

When the server is started with --requirepass <PASSWORD>, all REST API requests must include a Bearer token in the Authorization header. Without the flag, no authentication is required.

# With authentication enabled (--requirepass secret123)
curl -H "Authorization: Bearer secret123" \
http://localhost:5020/kv/mykey
{"result":"hello"}
# Missing or invalid token returns 401
curl http://localhost:5020/kv/mykey
{"error":"Unauthorized"}

Key-Value (Strings)

GET
/kv/:key

Get the value of a key. Returns 404 if key does not exist.

PUT
/kv/:key

Set a key to a string value with optional TTL.

{"value": "hello", "ex": 3600}
ex = TTL in seconds, px = TTL in milliseconds (optional)
DELETE
/kv/:key

Delete a key. Returns the count of keys deleted.

Lists

GET
/list/:key?start=0&stop=-1

Get a range of elements from the list (LRANGE). Defaults to all elements.

POST
/list/:key/lpush

Push values to the head of the list. Returns new list length.

{"values": ["a", "b", "c"]}
POST
/list/:key/rpush

Push values to the tail of the list. Returns new list length.

{"values": ["x", "y"]}
POST
/list/:key/lpop

Remove and return the first element.

POST
/list/:key/rpop

Remove and return the last element.

Hashes

GET
/hash/:key

Get all fields and values (HGETALL).

GET
/hash/:key/:field

Get a single field value (HGET).

PUT
/hash/:key

Set one or more hash fields (HSET).

{"fields": {"name": "Alice", "age": "30"}}
DELETE
/hash/:key/:field

Delete a hash field (HDEL).

Sets

GET
/set/:key

Get all members (SMEMBERS).

PUT
/set/:key

Add members (SADD). Returns count of new members added.

{"members": ["redis", "nosql", "fast"]}
DELETE
/set/:key/:member

Remove a member (SREM).

Sorted Sets

GET
/zset/:key?start=0&stop=-1

Get members with scores in rank order (ZRANGE WITHSCORES).

PUT
/zset/:key

Add members with scores (ZADD).

{"members": [{"score": 100, "member": "alice"}, {"score": 200, "member": "bob"}]}

HyperLogLog

POST
/pfadd/:key

Add elements to a HyperLogLog. Returns 1 if any register was altered, 0 otherwise.

{"elements": ["alice", "bob", "charlie"]}
GET
/pfcount/:key

Return the approximate cardinality of the HyperLogLog.

POST
/pfmerge/:dest

Merge multiple HyperLogLogs into a destination key.

{"sources": ["hll1", "hll2"]}

Bloom Filter

POST
/bf/reserve/:key

Create an empty Bloom filter with a given error rate and capacity.

{"error_rate": 0.001, "capacity": 10000}
POST
/bf/add/:key

Add an item to the Bloom filter. Returns 1 if newly added, 0 if it may have existed.

{"item": "hello"}
GET
/bf/exists/:key/:item

Check if an item may exist in the filter. Returns 1 (maybe exists) or 0 (definitely not).

GET
/bf/info/:key

Return information about a Bloom filter (capacity, size, filters, items inserted).

Geospatial

POST
/geo/:key/add

Add geospatial items (longitude, latitude, member) to a sorted set.

{"members": [{"longitude": 13.361389, "latitude": 38.115556, "member": "Palermo"}]}
GET
/geo/:key/pos/:member

Return the longitude and latitude of a member.

GET
/geo/:key/dist/:member1/:member2?unit=km

Return the distance between two members. Unit: m, km, ft, mi (default: m).

POST
/geo/:key/search

Search for members within a radius or bounding box.

{"longitude": 15, "latitude": 37, "radius": 200, "unit": "km", "count": 10, "sort": "ASC", "withcoord": true, "withdist": true}

GEOHASH and GEOSEARCHSTORE are available via the POST /cmd generic endpoint.

Bitmap

POST
/bitmap/:key/setbit

Set or clear the bit at offset. Returns the original bit value.

{"offset": 7, "value": 1}
GET
/bitmap/:key/getbit/:offset

Returns the bit value at offset. Returns 0 if key missing or offset beyond length.

GET
/bitmap/:key/bitcount?start=N&end=N

Count set bits in the string. Optional start/end specify a byte range.

BITOP is available via the POST /cmd generic endpoint.

Generic Command Endpoint

Execute any Redis command via HTTP. This gives you access to all 100+ commands without needing dedicated REST endpoints.

POST
/cmd

Execute any command by name with arguments.

{"command": "HSET", "args": ["user:1", "name", "Alice", "age", "30"]}

Server

GET
/info

Server information (equivalent to INFO command)

GET
/dbsize

Returns the number of keys in the database

Example Session

Terminal
# Set a key with 1-hour TTL
curl -X PUT http://localhost:5020/kv/session:abc \
-H "Content-Type: application/json" \
-d '{"value":"token123","ex":3600}'
{"result":"OK"}
# Get a key
curl http://localhost:5020/kv/session:abc
{"result":"token123"}
# Push to a list
curl -X POST http://localhost:5020/list/queue/rpush \
-H "Content-Type: application/json" \
-d '{"values":["job1","job2","job3"]}'
{"result":3}
# Set hash fields
curl -X PUT http://localhost:5020/hash/user:1 \
-H "Content-Type: application/json" \
-d '{"fields":{"name":"Alice","age":"30"}}'
{"result":2}
# Get all hash fields
curl http://localhost:5020/hash/user:1
{"result":["name","Alice","age","30"]}
# Execute any command via /cmd
curl -X POST http://localhost:5020/cmd \
-H "Content-Type: application/json" \
-d '{"command":"ZADD","args":["leaderboard","100","alice","200","bob"]}'
{"result":2}