Implement API to serve Playground CLI requests
Description
DiceDB Playground is an interactive platform that allows users to experiment with DiceDB commands in a live environment, similar to the Go Playground. Users will be able to submit and execute commands directly through a web interface. The initial implementation will focus on enabling users to search for and trigger commands.
For more details about DiceDB playground you can check here.
We need to implement an HTTP service that handles CLI requests for the DiceDB Playground. The service will be responsible for parsing incoming HTTP requests at the /cli endpoint, executing the appropriate DiceDB commands, and returning the command responses in a structured format. The primary goal is to enable CLI-based interactions with DiceDB via the Playground interface.
This service will:
- Parse incoming requests containing a command name and associated parameters.
- Send the appropriate command to the DiceDB instance using the Go SDK.
- Return the result of the command execution as the HTTP response.
- Note:
QWATCH/QUNWATCH/ABORT/BGREWRITEAOFthese commands won't be supported as part of this.
The API will follow the REST pattern and use the POST method to pass command information.
Note: Implementation will be part of DiceDB playground backend repo.
API details
Endpoint:
POST https://<BACKEND_SERVER_URL>/cli/<COMMAND_NAME>
Request Body Format:
{
"key": "<KEY_NAME>", "value": "<VALUE>"}
COMMAND_NAME: The DiceDB command being triggered (e.g., SET, GET, HSET, etc.).
KEY_NAME: The key for the command.
VALUE: The value to be set or retrieved, depending on the command.
Few example requests:
1. SET Command with NX Flag
-
URL:
POST https://<BACKEND_SERVER_URL>/cli/set -
Body:
{ "key": "k1", "value": "v1", "nx": "true" } -
Response:
{ "result": "OK" }
2. GET Command
-
URL:
POST https://<BACKEND_SERVER_URL>/cli/get -
Body:
{ "key": "k1" } -
Response:
{ "value": "v1" }
3. DEL Command
-
URL:
POST https://<BACKEND_SERVER_URL>/cli/del -
Body:
{ "keys": ["k1", "k2", "k3"] } -
Response:
{ "result": "OK" }
Tasks
- Service Implementation:
- Implementation will be done as part of
playground-backendrepository. - Create a new handler for the
/cliendpoint in the backend Golang server. - Parse the command name and associated parameters from the incoming request.
- Communicate with the DiceDB instance using the Go SDK to execute the command based on the parsed input.
- Return the result of the command in the response.
- Handle error cases, including invalid commands, missing parameters, and backend communication failures.
- Validation:
- Validate the incoming request to ensure required parameters (
key,value,COMMAND_NAME) are provided. - Ensure appropriate HTTP response codes are returned based on success or failure scenarios.
Hey @lucifercr07 I would like to take this up.
can I take this up? @lucifercr07
@Dev79844 assigned, thanks for contributing. Please let me know if any other details required.
@Dev79844 Please let me know if we can collaborate on this together this will also help in the #731 as that issue is dependent on this one.
Sure we can collaborate together
hey @Dev79844 i already wrote the API routes. we can collab. I've raised the PR for initial struct (without 727 changes) : https://github.com/DiceDB/playground-mono/pull/1
Hey @rishavvajpayee! Sure. I will add more code today.
sure @Dev79844 do let me know if i can help 👍
Closed as part of https://github.com/DiceDB/playground-mono/pull/4