dice icon indicating copy to clipboard operation
dice copied to clipboard

Implement API to serve Playground CLI requests

Open lucifercr07 opened this issue 1 year ago • 8 comments

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/BGREWRITEAOF these 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

  1. Service Implementation:
  • Implementation will be done as part of playground-backend repository.
  • Create a new handler for the /cli endpoint 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.
  1. 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.

lucifercr07 avatar Sep 26 '24 12:09 lucifercr07

Hey @lucifercr07 I would like to take this up.

Dev79844 avatar Sep 26 '24 12:09 Dev79844

can I take this up? @lucifercr07

RishabhC-137 avatar Sep 26 '24 13:09 RishabhC-137

@Dev79844 assigned, thanks for contributing. Please let me know if any other details required.

lucifercr07 avatar Sep 26 '24 13:09 lucifercr07

@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.

karandixit10 avatar Sep 26 '24 13:09 karandixit10

Sure we can collaborate together

Dev79844 avatar Sep 26 '24 15:09 Dev79844

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

rishavvajpayee avatar Sep 26 '24 17:09 rishavvajpayee

Hey @rishavvajpayee! Sure. I will add more code today.

Dev79844 avatar Sep 27 '24 02:09 Dev79844

sure @Dev79844 do let me know if i can help 👍

rishavvajpayee avatar Sep 27 '24 07:09 rishavvajpayee

Closed as part of https://github.com/DiceDB/playground-mono/pull/4

lucifercr07 avatar Sep 28 '24 17:09 lucifercr07