Interface regulations

Last Updated: Apr 19, 2017

Though SDKs in different languages are implemented differently, all their APIs comply with the request-response principle and are called in the following process:

  1. Construct a request instance by using request parameters.
  2. Call the corresponding interface in the SDK and input the request instance.
  3. Encapsulate the results returned by the SDK interface into a response instance and return the instance to the user.

The code snippets below explain how to obtain the names of all LogStores under a project based on the preceding process.

Java

  1. // Other code......
  2. String accessId = "your_access_id"; //TODO: Use your Alibaba Cloud access key ID.
  3. String accessKey = "your_access_key"; //TODO: Use your Alibaba Cloud access key secret.
  4. String project = "your_project"; //TODO: Use your project name.
  5. String endpoint = "region_endpoint";//TODO: Use the endpoint corresponding to the region where your project is located.
  6. //Construct a client instance.
  7. Client client = new Client(endpoint, accessId, accessKey);
  8. //Use the request parameter "project" to initialize a ListLogstores request class.
  9. ListLogStoresRequest lsRequest = new ListLogStoresRequest(project);
  10. //Use the request instance to call the ListLogstores interface. The return parameter is the corresponding response instance.
  11. ListLogStoresResponse res = client.ListLogStores(lsRequest);
  12. //Access the response instance to retrieve the request results
  13. ArrayList<String> names = res.GetLogStores();
  14. // Other code......

.NET (C#)

  1. // Other code......
  2. String accessId = "your_access_id"; //TODO: Use your Alibaba Cloud access key ID.
  3. String accessKey = "your_access_key"; //TODO: Use your Alibaba Cloud access key secret.
  4. String project = "your_project"; //TODO: Use your project name.
  5. String endpoint = "region_endpoint";//TODO: Use the endpoint corresponding to the region where your project is located.
  6. //Construct a client instance.
  7. SLSClient client = new SLSClient(endpoint, accessId, accessKey);
  8. //Use the request parameter "project" to initialize a ListLogstores request class.
  9. ListLogStoresRequest lsRequest = new ListLogStoresRequest();
  10. lsRequest.Project = project;
  11. //Use the request instance to call the ListLogstores interface. The return parameter is the corresponding response instance.
  12. ListLogStoresResponse res = client.ListLogStores(lsRequest);
  13. //Access the response instance to retrieve the request results
  14. List<String> names = res.Logstores;
  15. // Other code......

PHP

  1. // Other code......
  2. $accessId = "your_access_id"; //TODO: Use your Alibaba Cloud access key ID.
  3. $accessKey = "your_access_key"; //TODO: Use your Alibaba Cloud access key secret.
  4. $project = "your_project"; //TODO: Use your project name.
  5. $endpoint = "region_endpoint";//TODO: Use the endpoint corresponding to the region where your project is located.
  6. //Construct a Log Service client instance.
  7. $client = new Aliyun_Sls_Client($endpoint, $accessId, $accessKey);
  8. //Use the request parameter "project" to initialize a ListLogstores request class.
  9. $request = new Aliyun_Sls_Models_ListLogstoresRequest($project);
  10. //Use the request instance to call the ListLogstores interface. The return parameter is the corresponding response instance.
  11. $response = $client->listLogstores($request);
  12. //Access the response instance to retrieve the request results
  13. $names = $response->getLogstores();
  14. // Other code......

Python

  1. // Other code......
  2. accessId = 'your_access_id'; //TODO Use your Alibaba Cloud access key ID.
  3. accessKey = 'your_access_key'; //TODO Use your Alibaba Cloud access key secret.
  4. project = 'your_project'; //TODO: Use your project name.
  5. endpoint = 'region_endpoint';//TODO Use the endpoint corresponding to the region where your project is located.
  6. # Construct a client
  7. client = LogClient(endpoint, accessId, accessKey)
  8. # Use the request parameter "project" to initialize a ListLogstores request class.
  9. lsRequest = ListLogstoresRequest(project)
  10. # Use the request instance to call the ListLogstores interface. The return parameter is the corresponding response instance.
  11. res = client.list_logstores(lsRequest)
  12. # Access the response instance to retrieve the request results
  13. names = res.get_logstores();
  14. // Other code......

The SDKs provide multiple sets of interfaces similar to ListLogStores and define the corresponding request and response classes. In addition to the basic request-response interfaces, the SDKs in different languages provide secondary interfaces encapsulated with these basic interfaces, removing the need to construct requests and parse the final response. For details about the secondary interfaces, refer to the API reference of each SDK.

Thank you! We've received your feedback.