HTTP
Table of Contents
Section titled “Table of Contents”Introduction
Section titled “Introduction”DiceDB supports HTTP protocol for clients to connect to the database. This allows clients to connect to DiceDB over the web stack, enabling frontends to have direct access to DiceDB.
API Endpoint
Section titled “API Endpoint”All requests should be sent to the base URL of your server, followed by the command name:
http://your-server-address:port/<command>
General Request Structure
Section titled “General Request Structure”- HTTP Method: POST for all operations
- Path: The DiceDB command name (e.g.,
/GET
,/SET
,/HGET
) - Headers:
Content-Type: application/json
- Body: JSON object containing command arguments
Query Parameters
Section titled “Query Parameters”Certain commands may require additional query parameters. For example:
key_prefix
: Used for theJSON.INGEST
command to specify a key prefix
These will be specified in the command documentation.
Supported Commands
Section titled “Supported Commands”Our HTTP API supports all DiceDB commands. Please refer to our comprehensive command reference for each command, commands which lack support will be flagged as such.
Examples
Section titled “Examples”Setting a Key-Value Pair
Section titled “Setting a Key-Value Pair”Request:
POST /SET HTTP/1.1Host: your-server-addressContent-Type: application/json
{"key": "mykey","value": "Hello, World!"}
curl --location 'http://your-server-address:PORT/SET' \--header 'Content-Type: application/json' \--data '{ "key": "mykey", "value": "Hello, World!"}'
Response:
{ "status": "success", "data": "OK"}
Getting a Value
Section titled “Getting a Value”Request:
POST /GET HTTP/1.1Host: your-server-addressContent-Type: application/json
{"key": "mykey"}
curl --location 'http://your-server-address:PORT/GET' \--header 'Content-Type: application/json' \--data '{ "key": "mykey"}'
Response:
{ "status": "success", "data": "Hello, World!"}
Setting a field in Hash
Section titled “Setting a field in Hash”Request:
POST /HSET HTTP/1.1Host: your-server-addressContent-Type: application/json
{"key": "test","field": "test","value": "test"}
curl --location 'http://your-server-address:PORT/HSET' \--header 'Content-Type: application/json' \--data '{ "key": "test", "field": "test", "value": "test"}'
Response:
{ "status": "success", "data": 1}
Getting a field in a HashSet
Section titled “Getting a field in a HashSet”Request:
POST /HGET HTTP/1.1Host: your-server-addressContent-Type: application/json
{"key": "test","field": "test"}
curl --location 'http://your-server-address:PORT/HGET' \--header 'Content-Type: application/json' \--data '{ "key": "test", "field": "test"}'
Response:
{ "status": "success", "data": "test"}