Deploy your API in Choreo Connect using WSO2 APICTL

Rusiri Illesinghe
3 min readNov 14, 2023

--

Photo by Iván Díaz on Unsplash

Choreo Connect is an open source and cloud native api gateway powered by Envy proxy.

This is how the official docs explain the key capabilities of Choreo Connect!

It provides first-class support for Kubernetes while facilitating an array of API management quality of services (QoS), such as message security rate-limiting, observability, and message mediation.

Before Choreo Connect came onto the ground, WSO2 API Micro Gateway played a remarkable role as an immutable API gateway. Choreo Connect can be described as an enhanced version of it, which includes API hot deployment, message transformation with request-response interceptors etc. Further, Choreo connect consists of following 03 items :

i. Router — Routes the traffic from different clients to the desired destination (service)

ii. Enforcer — Enforces the API management capabilities such as security, Rate Limiting, analytics, validation and etc

iii. Adapter — Translates the API definition as to be able to understand by the router, when deploying the API in Choreo Connect.

Let’s see how you can use Choreo Connect with WSO2 API Controller. (APICTL). APICTL is a command line tool which allows you to communicate with a gateway with the commands it provides.

1. Start Choreo Connect

  1. Download Choreo Connect at here
  2. Extract the choreo-connect zip file.
  3. Open a terminal at <CHOREO-CONNECT_HOME>/docker-compose/choreo-connect/ and execute the following command to start Choreo Connect on Docker Compose :
docker-compose up -d

This will start the enforcer, adapter and router in separate containers. You can check the status of all containers with the following command :

docker ps | grep choreo-connect-

2. Managing the the APIs

We can deploy/ undeploy APIs to Choreo Connect gateway using apictl.

  1. Download APICTL at here
  2. Add the Choreo Connect Cluster as an Environment to apictl
  3. Create adapter environment in APICTL if it does not already exist
apictl mg add env dev --adapter <URL of the Adapter>

4. Login in to the adapter environment. (for this demonstration we are ignoring the SSL verification with -k option

apictl mg login dev -u admin -p admin -k

5. Now let’s initialize our API project with sample swagger definition ‘Petstore’ . You can use your own swagger file instead of that

apictl init <path_you_want_to_save_the_apiproject>/petstore --oas https://petstore.swagger.io/v2/swagger.json

6. Now let’s deploy the petstore API we created in the above step, in Choreo Connect

apictl mg deploy api -f <path_you_saved_the_apiproject>/petstore -e dev -k

We are almost done! Now let’s try invoking the API that that we deployed in Choreo Connect!

We need to have a valid access token or a test key to invoke the API.

In this example I’m using the test key endpoint of Choreo Connect to get a test key.

TOKEN=$(curl -X POST "https://localhost:9095/testkey" -d "scope=read:pets" -H "Authorization: Basic YWRtaW46YWRtaW4=" -k -v)

Now let’s invoke the API!

curl -X GET "https://localhost:9095/<API-context>/<API-resource>" -H "Authorization: Bearer $TOKEN" -k

You can undeploy the API when you need, using the following command

apictl mg undeploy api --environment dev -n <API Name> -v <API Version> -k

Here we came to the end! See you next time!

--

--