Skip to content

Commit

Permalink
#1113 Add cURL Examples to HTTP Docs (#1120)
Browse files Browse the repository at this point in the history
  • Loading branch information
vanshavenger authored Oct 17, 2024
1 parent 373e868 commit c9170f1
Showing 1 changed file with 117 additions and 24 deletions.
141 changes: 117 additions & 24 deletions docs/src/content/docs/protocols/http.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ sidebar:
order: 1
---

import { Tabs, TabItem } from '@astrojs/starlight/components';

## Table of Contents

1. [Introduction](#introduction)
Expand Down Expand Up @@ -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
<Tabs syncKey="http-request-format">
<TabItem label="HTTP Request">
```http
POST /SET HTTP/1.1
Host: your-server-address
Content-Type: application/json
{
"key": "mykey",
"value": "Hello, World!"
}
```
</TabItem>
<TabItem label="cURL">
```bash
curl --location 'http://your-server-address:PORT/SET' \
--header 'Content-Type: application/json' \
--data '{
"key": "mykey",
"value": "Hello, World!"
}'
```
</TabItem>
</Tabs>

{
"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
<Tabs syncKey="http-request-format">
<TabItem label="HTTP Request">
```http
POST /GET HTTP/1.1
Host: your-server-address
Content-Type: application/json
{
"key": "mykey"
}
```
</TabItem>
<TabItem label="cURL">
```bash
curl --location 'http://your-server-address:PORT/GET' \
--header 'Content-Type: application/json' \
--data '{
"key": "mykey"
}'
```
</TabItem>
</Tabs>

{
"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:**
<Tabs syncKey="http-request-format">
<TabItem label="HTTP Request">
```http
POST /HSET HTTP/1.1
Host: your-server-address
Content-Type: application/json
{
Expand All @@ -99,34 +140,72 @@ Content-Type: application/json
"value": "test"
}
```
</TabItem>
<TabItem label="cURL">
```bash
curl --location 'http://your-server-address:PORT/HSET' \
--header 'Content-Type: application/json' \
--data '{
"key": "test",
"field": "test",
"value": "test"
}'
```
</TabItem>
</Tabs>


**Response:**
```json
1
{
"status": "success",
"data": 1
}
```

### Getting a field in a HashSet

**Request:**
<Tabs syncKey="http-request-format">
<TabItem label="HTTP Request">
```http
POST http://localhost:8082/hget HTTP/1.1
POST /HGET HTTP/1.1
Host: your-server-address
Content-Type: application/json
{
"key": "test",
"field": "test"
}
```
</TabItem>
<TabItem label="cURL">
```bash
curl --location 'http://your-server-address:PORT/HGET' \
--header 'Content-Type: application/json' \
--data '{
"key": "test",
"field": "test"
}'
```
</TabItem>
</Tabs>

**Response:**
```json
"test"
{
"status": "success",
"data": "test"
}
```

### QWATCH Example

**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:**
<Tabs syncKey="http-request-format">
<TabItem label="HTTP Request">
```http
POST /QWATCH HTTP/1.1
Host: your-server-address
Expand All @@ -137,3 +216,17 @@ Content-Type: application/json
}
```

</TabItem>
<TabItem label="cURL">
```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"
}'
```
</TabItem>
</Tabs>



0 comments on commit c9170f1

Please sign in to comment.