All Products
Search
Document Center

Simple Log Service:Operation specifications

Last Updated:Jul 10, 2024

This topic describes the specifications that you must follow when you use Simple Log Service SDK to call API operations.

Request-response basics

SDK implementations vary based on the programming language. However, all API operations that are encapsulated in Simple Log Service SDK follow the same request-response basics. The following list describes the procedure for calling an API operation:

  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 code snippets demonstrate how to retrieve the names of all Logstores in a project.

// Other code. 
// Configure environment variables. In this example, the AccessKey ID and AccessKey secret are obtained from environment variables. 
String accessId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
String accessKey = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
// The name of the project.    
String project = "your_project";
// The Simple Log Service endpoint. 
String endpoint = "region_endpoint";
// Create a client. 
Client client = new Client(endpoint, accessId, accessKey);
// Specify the project parameter to create a request class for the ListLogstores operation. 
ListLogStoresRequest lsRequest = new ListLogStoresRequest(project, 0,100, "");
// Use the request object to call the ListLogstores operation. The response object is returned. 
ListLogStoresResponse res = client.ListLogStores(lsRequest);
// Parse the response object to retrieve the request results. 
ArrayList<String> names = res.GetLogStores();
// Other code.
// Other code. 
// Configure environment variables. In this example, the AccessKey ID and AccessKey secret are obtained from environment variables. 
String accessId = Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_ID"); 
String accessKey = Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
// The name of the project. 
String project = "your_project";
// The Simple Log Service endpoint. 
String endpoint = "region_endpoint";
// Create a client. 
SLSClient client = new SLSClient(endpoint, accessId, accessKey);
// Specify the project parameter to create a request class for the ListLogstores operation. 
ListLogStoresRequest lsRequest = new ListLogStoresRequest();
lsRequest.Project = project;
// Use the request object to call the ListLogstores operation. The response object is returned. 
ListLogStoresResponse res = client.ListLogStores(lsRequest);
// Parse the response object to retrieve the request results. 
List<String> names = res.Logstores;
// Other code.
// Other code. 
// Configure environment variables. In this example, the AccessKey ID and AccessKey secret are obtained from environment variables. 
$accessId = getenv('ALIBABA_CLOUD_ACCESS_KEY_ID'); 
$accessKey = getenv('ALIBABA_CLOUD_ACCESS_KEY_SECRET');
// The name of the project. 
$project = "your_project";
// The Simple Log Service endpoint. 
$endpoint = "region_endpoint";
// Create a client. 
$client = new Aliyun_Sls_Client($endpoint, $accessId, $accessKey);
// Specify the project parameter to create a request class for the ListLogstores operation. 
$request = new Aliyun_Sls_Models_ListLogstoresRequest($project);
// Use the request object to call the ListLogstores operation. The response object is returned. 
$response = $client->listLogstores($request);
// Parse the response object to retrieve the request results. 
$names = $response->getLogstores();
// Other code.
# Other code. 
# Configure environment variables. In this example, the AccessKey ID and AccessKey secret are obtained from environment variables. 
accessId = os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_ID', '');
accessKey = os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_SECRET', '');
# The name of the project. 
project = 'your_project'; 
# The Simple Log Service endpoint. 
endpoint = 'region_endpoint';
# Create a client. 
client = LogClient(endpoint, accessId, accessKey)
# Specify the project parameter to create a request class for the ListLogstores operation. 
lsRequest = ListLogstoresRequest(project)
# Use the request object to call the ListLogstores operation. The response object is returned. 
res = client.list_logstores(lsRequest)
# Parse the response object to retrieve the request results. 
names = res.get_logstores();
# Other code.

Simple Log Service SDK defines request and response classes for API operations that are similar to the ListLogStores operation. In addition to the basic API operations that follow the request-response basics, Simple Log Service SDK in different programming languages provides secondary API operations into which the basic API operations are packaged. You do not need to manually create request objects or parse response objects. For more information, see SDK Reference.