API specification

Updated at:

This topic describes the principles of SDK interfaces.

Request-response principle

SDK implementations differ across languages, but all interfaces follow the request-response principle. API calls proceed as follows:

  1. Build a Request instance with the request parameters.

  2. Call the corresponding SDK interface and pass the Request instance to it.

  3. The SDK interface returns the result as a Response instance.

Example

The following code snippet shows how to retrieve a paginated list of all devices in Resource Management.

// 1. Create and initialize a Config instance.
Config authConfig = new Config();
/**
 *  An Alibaba Cloud account AccessKey has permissions for all APIs. Use a Resource Access Management (RAM) user for API calls or daily O&M.
 *  Do not save your AccessKey ID and AccessKey secret in your project code. This can lead to an AccessKey leak and compromise the security of all resources in your account.
 *  Configure identity authentication before you call an API. For more information, see https://help.aliyun.com/document_detail/378657.html.
 *  This example uses the Alibaba Cloud Credentials tool to manage the AccessKey for API access authentication.
 */
com.aliyun.credentials.Client credentialClient = new com.aliyun.credentials.Client();
authConfig.endpoint = "region_endpoint"; // Set the endpoint and connection type as needed.
authConfig.regionId = "cn-hangzhou"; // Set the region as needed.
authConfig.setCredential(credentialClient);
Client authClient = new Client(authConfig);

// 2. Create an API request and set the parameters.
// Initialize the request class for ListDevices.
ListDevicesRequest request = new ListDevicesRequest();
request.setMaxResults(10);  // Paging parameter. Retrieves 10 rows per page.
request.setDeviceFormName("Network Device");  // The device form name. Set the device form as needed.
// Call the ListDevices interface with the request instance. The interface returns a Response instance.
ListDevicesResponse response = authClient.listDevices(request);
// Other code.