Skip to content

HTTP

Table of Contents

  1. Introduction
  2. API Endpoint
  3. General Request Structure
  4. Supported Commands
  5. Examples

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, which is currently not possible with Redis.

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

  • 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

Certain commands may require additional query parameters. For example:

  • key_prefix: Used for the JSON.INGEST command to specify a key prefix

These will be specified in the command documentation.

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

Setting a Key-Value Pair

Request:

POST /SET HTTP/1.1
Host: your-server-address
Content-Type: application/json
{
"key": "mykey",
"value": "Hello, World!"
}

Response:

{
"status": "success",
"data": "OK"
}

Getting a Value

Request:

POST /GET HTTP/1.1
Host: your-server-address
Content-Type: application/json
{
"key": "mykey"
}

Response:

{
"status": "success",
"data": "Hello, World!"
}

Setting a field in Hash

Request:

POST /HSET HTTP/1.1
Host: your-server-address
Content-Type: application/json
{
"key": "test",
"field": "test",
"value": "test"
}

Response:

{
"status": "success",
"data": 1
}

Getting a field in a HashSet

Request:

POST /HGET HTTP/1.1
Host: your-server-address
Content-Type: application/json
{
"key": "test",
"field": "test"
}

Response:

{
"status": "success",
"data": "test"
}