All Products
Search
Document Center

Alibaba Cloud SDK:Automatic generation of SDK examples

Last Updated:Jul 03, 2023

This topic describes how to automatically generate SDK examples for specific API operations in OpenAPI Portal.

Scenario

This topic uses the DescribeAvailableResource operation as an example to describe how to automatically generate an SDK for Java code example. The DescribeAvailableResource operation is used to query the resources in a zone.

Procedure

1. Download a sample SDK project

Note

If this is your first time using an Alibaba Cloud SDK, you can perform the following steps to download a complete sample SDK project. The SDK project package includes data such as dependencies, request parameters, requests, and responses.

  1. Open OpenAPI Portal.

  2. Perform the steps shown in the following figure to download a sample SDK project.

image.png

The following table explains the specific operations of each number in the above figure.

No.

Operations

Click Select a cloud serviceimage.png in the top navigation bar of the OpenAPI Portal homepage. Then, enter the name of the cloud service you want to use in the search box. Elastic Compute Service (ECS) is used in this example.

After you select the cloud service, click API Debugging in the top navigation bar of OpenAPI Portal.

Check the version of the API. The API version is 2014-05-26 in this example.

Enter the name of the API operation that you want to call in the search box. Then, click the specified API operation.

DescribeAvailableResource is used in this example.

Set the request parameters of the DescribeAvailableResource operation.

Optional. Call the API operation. You may be billed depending on the billing policy of the API operation.

In the upper part of the right-side area, click SDK Sample Code.

Select the SDK version and language based on your business requirements.

In this example, V2.0 is selected as the SDK version and Java is selected as the language.

Download the complete sample SDK project, including the display logic and the dependencies.

2. Copy the code example and the SDK information

Note

If you are familiar with Alibaba Cloud SDKs, you can copy the essential code logic without response or error displays.

  1. Open OpenAPI Portal.

  2. Perform the steps shown in the following figure to obtain the SDK information and a code example.

image.png

The following table explains the specific operations of each number in the above figure.

No.

Operations

Click Select a cloud serviceimage.png in the top navigation bar of the OpenAPI Portal homepage. Then, enter the name of the cloud service you want to use in the search box. ECS is used in this example.

After you select the cloud service, click API Debugging in the top navigation bar of OpenAPI Portal.

Check the version of the API. The API version is 2014-05-26 in this example.

Enter the name of the API operation that you want to call in the search box. Then, click the specified API operation.

DescribeAvailableResource is used in this example.

Set the request parameters of the DescribeAvailableResource operation.

Optional. Call the API operation. You may be billed depending on the billing policy of the API operation.

In the upper part of the right-side area, click SDK Sample Code.

Select the SDK version and language based on your business requirements.

In this example, V2.0 is selected as the SDK version and Java is selected as the language.

View the SDK information to obtain the dependency installation command and the release report.

Copy the code example displayed on the page. The code example does not include the error or response display logic.

Note
  • In the upper-right corner of the editor, you can click the 复制..png icon to copy the SDK code example.

  • In the upper part of the SDK Sample Code tab, you can click Download Project to download the complete sample SDK project.