This topic describes the procedure that you must follow when you use an SDK to call API operations.

Request-response basics

The implementation of SDKs varies depending on programming languages. However, the procedure that you implement by using SDKs to call API operations follow the same request-response basics:
  1. Specify parameters to create a request object.
  2. Use the request object to call an API operation.
  3. The request results are returned as a response object.

Examples

The following snippets show how to retrieve the names of all Logstores in a project based on the preceding procedure:
  • Java
    // Other pieces of code.
    String accessId = "your_access_id";     // The AccessKey ID of your Alibaba Cloud account.
    String accessKey = "your_access_key";   // The AccessKey secret of your Alibaba Cloud account.
    String project = "your_project";        // The name of the project that you need to access.
    String endpoint = "region_endpoint";// The endpoint of the project that you need to access. Specify the endpoint based on the access method and the region that the project resides.
    // Create a client object.
    Client client = new Client(endpoint, accessId, accessKey);
    // Specify the project parameter to create a ListLogstores request object.
    ListLogStoresRequest lsRequest = new ListLogStoresRequest(project);
    //Use the request object to call the ListLogstores API operation. The returned parameter is a response object.
    ListLogStoresResponse res = client.ListLogStores(lsRequest);
    // Parse the response object to retrieve the request results.
    ArrayList<String> names = res.GetLogStores();
    // Other pieces of code.
  • .NET(C#)
    // Other pieces of code.
    String accessId = "your_access_id";     // The AccessKey ID of your Alibaba Cloud account.
    String accessKey = "your_access_key";   // The AccessKey secret of your Alibaba Cloud account.
    String project = "your_project";        // The name of the project that you need to access.
    String endpoint = "region_endpoint";// The endpoint of the project that you need to access. Specify the endpoint based on the access method and the region that the project resides.
    // Create a client object.
    SLSClient client = new SLSClient(endpoint, accessId, accessKey);
    // Specify the project parameter to create a ListLogstores request object.
    ListLogStoresRequest lsRequest = new ListLogStoresRequest();
    lsRequest.Project = project;
    //Use the request object to call the ListLogstores API operation. The returned parameter is a response object.
    ListLogStoresResponse res = client.ListLogStores(lsRequest);
    // Parse the response object to retrieve the request results.
    List<String> names = res.Logstores;
    // Other pieces of code.
  • PHP
    // Other pieces of code.
    accessId = "your_access_id"; // The AccessKey ID of your Alibaba Cloud account.
    $accessKey = "your_access_key"; // The AccessKey secret of your Alibaba Cloud account.
    $project = "your_project";        // The name of the project that you need to access.
    $endpoint = "region_endpoint";// The endpoint of the project that you need to access. Specify the endpoint based on the access method and the region that the project resides.
    //Create a client object.
    $client = new Aliyun_Sls_Client($endpoint, $accessId, $accessKey);
    // Specify the project parameter to create a ListLogstores request object.
    $request = new Aliyun_Sls_Models_ListLogstoresRequest($project);
    //Use the request object to call the ListLogstores API operation. The returned parameter is a response object.
    $response = $client->listLogstores($request);
    // Parse the response object to retrieve the request results.
    $names = $response->getLogstores();
    // Other pieces of code.
  • Python
    // Other pieces of code.
    accessId = 'your_access_id'; //The AccessKey ID of your Alibaba Cloud account.
    $accessKey = "your_access_key"; // The AccessKey secret of your Alibaba Cloud account.
    project = 'your_project';        // The name of the project that you need to access.
    endpoint = 'region_endpoint';// The endpoint of the project that you need to access. Specify the endpoint based on the access method and the region that the project resides.
    # Create a client object.
    client = LogClient(endpoint, accessId, accessKey)
    # Create an ListLogstores request object and initialize the project variable.
    lsRequest = ListLogstoresRequest(project)
    # Use the request object to call the ListLogstores API operation. The returned parameter is a response object.
    res = client.list_logstores(lsRequest)
    # Parse the response object to retrieve the request results.
    names = res.get_logstores();
    // Other pieces of code.

Log Service SDKs define request and response classes for API operations that are similar to the ListLogStores operation. You can use SDKs to call these API operations to list Logstores of a project. In addition to the basic API operations that follow the basic request-response basics, Log Service SDK for each programming language provides secondary API operations. These API operations are packaged with the basic API operations. You do not need to create request objects and parse response objects. For more information about these API operations, see API reference.