Build an HTTP Service With WSO2 Copilot¶
In this tutorial, you’ll create an HTTP service to add key-value pairs to a Redis database. The integrated AI-assistant will help you generate the integration flow.
Prerequisites¶
- Docker installed on your machine.
Step 1: Create a new integration project¶
- Click on the Ballerina Integrator icon on the sidebar.
- Click on the Create New Integration button.
- Enter the project name as
RedisService
. - Select project directory location by clicking on the Select Location button.
- Click on the Create New Integration button to create the integration project.
Step 2: Create a new integration¶
- In the design view click on the Generate with AI button.
-
Enter the following prompt and press
Enter
:Create an integration service with a base path of /cache and a POST resource at /add that accepts key-value pairs and adds them to Redis.
-
Click on + Add to Ingeration button to add the generated integration to the project.
-
The generated integration will look like below:
Step 3: Add a resource to get value¶
- Add the following prompt and press
Enter
:Add a resource to get the value of a key from Redis.
- Click on + Add to Ingeration button to add the generated integration to the project.
-
The generated integration will look like below:
Step 4: Start the Redis server¶
- Start the Redis server by running the following command:
docker run --name some-redis -d -p 6379:6379 redis
-
The redis server will start on port
6379
without password protection.
Step 6: Configure the Redis client¶
- In the
Integrator overview
, click on the Configurations. - Set
redisHost
value tolocalhost
. -
Set
redisPort
value to6379
.
Step 5: Generate the curl commands¶
-
Add the following prompt and press
Enter
to generate the curl command to add key-value pairs to the Redis server.:Generate a curl command to add key-value pairs to the Redis server.
-
Add the following prompt and press
Enter
to generate the curl command to get the value of a key from the Redis server.:Generate a curl command to get the value of a key from the Redis server.
Step 6: Test the integration¶
- Click on the Run button to start the integration.
- Execute the generated
curl
commands to add a key-value pair.curl -X POST http://localhost:8080/cache/add \ -H "Content-Type: application/json" \ -d '{"key": "BI", "value": "Ballerina Integrator is an AI-assisted integration platform."}'
- Execute the generated
curl
command to get the value of the key.curl http://localhost:8080/cache/get?key=BI
- The response will be the value of the key
BI
stored in the Redis server.Ballerina Integrator is an AI-assisted integration platform.%
Step 7: Stop the integration¶
- Click on the Stop button to stop the integration.
- Stop the Redis server by running the following command:
docker stop some-redis