DEV Community

loading...
Cover image for WSO2 API Cloud projects initialization and deployment using the CLI Tool

WSO2 API Cloud projects initialization and deployment using the CLI Tool

mihinduranasinghe profile image Mihindu Ranasinghe Updated on ・4 min read

WSO2 API Cloud delivers an enterprise-ready solution for creating, publishing, and managing all aspects of an API and its lifecycle. To register and get started with WSO2 API Cloud, go to http://wso2.com/cloud/api-cloud/

You can take a look at the WSO2 API Cloud Documentation to quickly try out designing , creating and publishing APIs from the Web UI, subscribing to it from the Web UI of the WSO2 API Cloud

In this article, we are focusing on Designing, Initializing and deploying APIs from the command line using the APIMCLI tool.

👉 Pre-requisites

1.Download API Controller based on your preferred platform (i.e., Mac, Windows, Linux).

2.Extract the downloaded archive containing the CLI Tool to a preferred location and navigate to it from the terminal (using cd ).

3.Navigate to the working directory where the executable CLI Tool resides.

4.Execute the following command to start the CLI tool.

./apimcli
Enter fullscreen mode Exit fullscreen mode

5.Add the location of the extracted folder to your system's $PATH variable to be able to access the executable from anywhere.

apimcli
Enter fullscreen mode Exit fullscreen mode

1. Adding the cloud gateway environment


apimcli add-env -n wso2apicloud \
                      --registration https://gateway.api.cloud.wso2.com/client-registration/register \
                      --apim https://gateway.api.cloud.wso2.com/pulisher \
                      --token https://gateway.api.cloud.wso2.com/token \
                      --import-export https://gateway.api.cloud.wso2.com/api-import-export \
                      --admin https://gateway.api.cloud.wso2.com/api/am/admin/ \
                      --api_list https://gateway.api.cloud.wso2.com/api/am/publisher/apis \
                      --app_list https://gateway.api.cloud.wso2.com/api/am/store/applications


Enter fullscreen mode Exit fullscreen mode
Make sure the environment is configured by this command :
apimcli list envs
Enter fullscreen mode Exit fullscreen mode

2. Create a new API project

Usage:

You can follow one of these example methods to initialize a project.

apimcli init [project path] [flags]
Examples:

# Initialize with default swagger.yaml file and default API definition (You have to replace the generated API definition and Swagger with your actual values)
apimcli init SampleStore
# Initialize with your actual swagger file path
apimcli init SampleStore --oas petstore.yaml
# Initialize with your actual swagger file URL
apimcli init SampleStore --oas https://petstore.swagger.io/v2/swagger.json
# Initialize with your actual swagger file and API Definition file
apimcli init SampleStore --oas ./swagger.yaml -d definition.yaml 

Enter fullscreen mode Exit fullscreen mode
A project folder with the following structure will be created in the given directory.

├── api_params.yaml
├── Docs
│ └── FileContents
├── Image
├── Meta-information
│ ├── api.yaml
│ └── swagger.yaml
├── README.md
└── Sequences
│ ├── fault-sequence
│ ├── in-sequence
│ └── out-sequence

I have attached 2 sample files for api.yaml and swagger.json for your reference.

You can get the hands-on experience by replacing below files with generated Meta-information in your directory and move forward with the article.

If you want to learn more on api.yaml configuration, here you can find out gist


3. Deploying the API project to a targeted tenant in API Cloud

  • First of all you need to log into your targeted tenant in API Cloud by providing targeted tenant username & password .
#apimcli login <Environment> -u <Username> -p <Password> 
apimcli login wso2apicloud -u mihindu@wso2.com@development -p PASS54687 -k

Enter fullscreen mode Exit fullscreen mode

Also you can login like this :

Alt Text

  • After logging in to the targeted tenant, you can import the API using the following command.

apimcli import-api -f ./path/SampleStore -e wso2apicloud --preserve-provider=false --update --verbose -k


Enter fullscreen mode Exit fullscreen mode
Make sure the API project is deployed successfully by this command :
# apimcli list apis -e <environment> -k
apimcli list apis -e wso2apicloud -k
Enter fullscreen mode Exit fullscreen mode
Here the deployed APIs are listed:

Alt Text

You can log into the WSO2 API cloud portal and see the project is deployed successfully.

Alt Text


How to export the API Project from the logged in tenant from the CLI ?


# # apimcli export-api -n <API-name> -v <version> -r <provider> -e <environment> -u <username> -p <password> -k
# # apimcli export-api --name <API-name> --version <version> --provider <provider> --environment <environment> --username <username> --password <password> --insecure
apimcli export-api -n SampleStore -v 1.0.0 -r mihindu@wso2.com@development -e wso2apicloud -k


Enter fullscreen mode Exit fullscreen mode
Once you exported successfully you will receive a response with the exported directory in your local machine.

Response :

Successfully exported API!
Find the exported API at /Users/kim/.wso2apimcli/exported/apis/dev/SampleStore_1.0.0.zip
Enter fullscreen mode Exit fullscreen mode

DO YOU KNOW

  • How to update an API Cloud Project Thumbnail from the CLI ?
  • How to add Mediation Sequences for the API Cloud Project from the CLI ?
  • How to add API Scopes from the CLI ?
  • How to add Documents for the API Cloud Project from the CLI ?
  • How to invoke an API in WSO2 API Cloud with a generated API Token, from the CLI ?

👉 What's Next?

Thank You

Hope you all enjoyed and learned something from this. Let me know your comments and suggestions in the discussion section.

👉 Visit me - https://mihinduranasinghe.com/

Discussion (0)

pic
Editor guide