From c9170f1f220c49e3f25817b77cb4e461a7b86009 Mon Sep 17 00:00:00 2001 From: Vansh Chopra <76000026+vanshavenger@users.noreply.github.com> Date: Thu, 17 Oct 2024 21:59:01 +0530 Subject: [PATCH] #1113 Add cURL Examples to HTTP Docs (#1120) --- docs/src/content/docs/protocols/http.mdx | 141 +++++++++++++++++++---- 1 file changed, 117 insertions(+), 24 deletions(-) diff --git a/docs/src/content/docs/protocols/http.mdx b/docs/src/content/docs/protocols/http.mdx index 1c0828a91..08d690399 100644 --- a/docs/src/content/docs/protocols/http.mdx +++ b/docs/src/content/docs/protocols/http.mdx @@ -5,6 +5,8 @@ sidebar: order: 1 --- +import { Tabs, TabItem } from '@astrojs/starlight/components'; + ## Table of Contents 1. [Introduction](#introduction) @@ -53,44 +55,83 @@ Our HTTP API supports all DiceDB commands. Please refer to our comprehensive com ### Setting a Key-Value Pair **Request:** -```http -POST /SET HTTP/1.1 -Host: your-server-address -Content-Type: application/json + + + ```http + POST /SET HTTP/1.1 + Host: your-server-address + Content-Type: application/json + + { + "key": "mykey", + "value": "Hello, World!" + } + ``` + + + ```bash + curl --location 'http://your-server-address:PORT/SET' \ + --header 'Content-Type: application/json' \ + --data '{ + "key": "mykey", + "value": "Hello, World!" + }' + ``` + + -{ - "key": "mykey", - "value": "Hello, World!" -} -``` **Response:** ```json -"OK" +{ + "status": "success", + "data": "OK" +} ``` ### Getting a Value **Request:** -```http -POST /GET HTTP/1.1 -Host: your-server-address -Content-Type: application/json + + + ```http + POST /GET HTTP/1.1 + Host: your-server-address + Content-Type: application/json + + { + "key": "mykey" + } + ``` + + + ```bash + curl --location 'http://your-server-address:PORT/GET' \ + --header 'Content-Type: application/json' \ + --data '{ + "key": "mykey" + }' + ``` + + -{ - "key": "mykey" -} -``` **Response:** ```json -"Hello, World!" +{ + "status": "success", + "data": "Hello, World!" +} ``` ### Setting a field in Hash -```http -POST http://localhost:8082/hset HTTP/1.1 +**Request:** + + + ```http +POST /HSET HTTP/1.1 +Host: your-server-address Content-Type: application/json { @@ -99,16 +140,37 @@ Content-Type: application/json "value": "test" } ``` + + + ```bash + curl --location 'http://your-server-address:PORT/HSET' \ + --header 'Content-Type: application/json' \ + --data '{ + "key": "test", + "field": "test", + "value": "test" + }' + ``` + + + **Response:** ```json -1 +{ + "status": "success", + "data": 1 +} ``` ### Getting a field in a HashSet +**Request:** + + ```http -POST http://localhost:8082/hget HTTP/1.1 +POST /HGET HTTP/1.1 +Host: your-server-address Content-Type: application/json { @@ -116,10 +178,25 @@ Content-Type: application/json "field": "test" } ``` + + + ```bash +curl --location 'http://your-server-address:PORT/HGET' \ +--header 'Content-Type: application/json' \ +--data '{ + "key": "test", + "field": "test" +}' +``` + + **Response:** ```json -"test" +{ + "status": "success", + "data": "test" +} ``` ### QWATCH Example @@ -127,6 +204,8 @@ Content-Type: application/json **NOTE**: The `QWATCH` command is asynchronous and requires the use of Server-Sent Events (SSE) to receive updates. The following example demonstrates how to use `QWATCH` with SSE. **Request:** + + ```http POST /QWATCH HTTP/1.1 Host: your-server-address @@ -137,3 +216,17 @@ Content-Type: application/json } ``` + + +```bash +curl --location 'http://your-server-address:PORT/QWATCH' \ +--header 'Content-Type: application/json' \ +--data '{ + "query": "SELECT $key, $value WHERE $key like '\''match:100:*'\'' AND $value > 10 ORDER BY $value DESC LIMIT 3" +}' +``` + + + + +