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
5.Add the location of the extracted folder to your system's $PATH variable to be able to access the executable from anywhere.
apimcli
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
Make sure the environment is configured by this command :
apimcli list envs
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
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
Also you can login like this :
- 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
Make sure the API project is deployed successfully by this command :
# apimcli list apis -e <environment> -k
apimcli list apis -e wso2apicloud -k
Here the deployed APIs are listed:
You can log into the WSO2 API cloud portal and see the project is deployed successfully.
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
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
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/
Top comments (0)