Este tópico descreve as especificações a seguir ao usar o SDK do Simple Log Service para chamar operações de API.
Fundamentos de requisição e resposta
As implementações do SDK variam conforme a linguagem de programação. No entanto, todas as operações de API encapsuladas no SDK do Simple Log Service seguem os mesmos fundamentos de requisição e resposta. O procedimento para chamar uma operação de API consiste nas etapas a seguir:
Especifique os parâmetros para criar um objeto de requisição.
Use o objeto de requisição para chamar uma operação de API.
Obtenha os resultados da requisição em um objeto de resposta.
Exemplos
Os trechos de código a seguir demonstram como recuperar os nomes de todos os Logstores em um projeto.
// 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.
O SDK do Simple Log Service define classes de requisição e resposta para operações de API semelhantes à operação ListLogStores. Além das operações básicas que seguem os fundamentos de requisição e resposta, o SDK oferece operações secundárias em diversas linguagens de programação. Essas operações encapsulam as chamadas básicas, eliminando a necessidade de criar objetos de requisição ou analisar objetos de resposta manualmente. Para mais informações, consulte Referência do SDK.