Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement API to serve Playground CLI requests #727

Closed
lucifercr07 opened this issue Sep 26, 2024 · 9 comments
Closed

Implement API to serve Playground CLI requests #727

lucifercr07 opened this issue Sep 26, 2024 · 9 comments

Comments

@lucifercr07
Copy link
Contributor

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.
@Dev79844
Copy link
Contributor

Hey @lucifercr07
I would like to take this up.

@RishabhC-137
Copy link

can I take this up? @lucifercr07

@lucifercr07
Copy link
Contributor Author

lucifercr07 commented Sep 26, 2024

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

@karandixit10
Copy link
Contributor

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

@Dev79844
Copy link
Contributor

Sure we can collaborate together

@rishavvajpayee
Copy link
Contributor

hey @Dev79844 i already wrote the API routes. we can collab.
I've raised the PR for initial struct (without 727 changes) : DiceDB/playground-mono#1

@Dev79844
Copy link
Contributor

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

@rishavvajpayee
Copy link
Contributor

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

@lucifercr07
Copy link
Contributor Author

Closed as part of DiceDB/playground-mono#4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants