All Products
Search
Document Center

Alibaba Cloud SDK:Configure a endpoint

Last Updated:Jun 25, 2024

This topic describes how to configure an endpoint in Alibaba Cloud Darabonba SDK.

Note

An endpoint is a domain name of an Alibaba Cloud service API. For example, an endpoint of Elastic Compute Service (ECS) can be ecs.cn-hangzhou.aliyuncs.com. Each Alibaba Cloud service has its unique endpoints. The endpoints of a service may vary based on regions.

Configure an endpoint to which API requests are sent

Darabonba SDK allows you to specify the endpoint to which API requests are sent in two modes. The following list describes the modes by priority in descending order:

  1. User-defined endpoint: In this mode, you can specify an exact endpoint when you initialize an SDK client. You can query an endpoint by visiting

    OpenAPI Explorer. For more information about how to query an endpoint in OpenAPI Explorer, see the "Query an endpoint" section of this topic.

use Darabonba\OpenApi\Models\Config;

$config = new Config([]);
// Omit the credential configuration.
$config->endpoint = "<endpoint>";

2. Concatenated endpoint: In this mode, you can specify a region ID for Darabonba SDK to generate an endpoint. This mode takes effect only if the SDK of an Alibaba Cloud service has an endpoint data file. Otherwise, an exception is thrown and the error message config.endpoint can not be empty is returned when you initialize an SDK client. In this case, you must specify an exact endpoint. For more information about an example of an endpoint data file, see ECS endpoint data file. If the region that you want to access is not included in the data file, the endpoint of the region is generated in the ${Code of the Alibaba Cloud service}.${Region ID}.aliyuncs.com format.

use Darabonba\OpenApi\Models\Config;

$config = new Config([]);
// Omit the credential configuration.
$config->regionId = "<region-id>";

3. Configure endpoints for uploading files

You can configure two endpoints for uploading files in Darabonba SDK.

- The endpoint of an open platform that is used for authentication. You can configure a virtual private cloud (VPC) endpoint to request authentication information over a VPC. The authentication information is used for file uploads.

use Darabonba\OpenApi\Models\Config;
use GuzzleHttp\Psr7\Stream;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
use AlibabaCloud\SDK\Facebody\V20191230\Facebody;
use AlibabaCloud\SDK\Facebody\V20191230\Facebody\Models\DetectBodyCountAdvanceRequest;

$config = new Config([]);
// Omit the credential configuration.
$config->regionId = "<region-id>";
$config->openPlatformEndpoint = "openplatform-vpc.cn-shanghai.aliyuncs.com";

$request = new DetectBodyCountAdvanceRequest();
$request->imageURLObject = new Stream(fopen("filepath"));

$runtime = new RuntimeOptions();
$client = new Facebody($config);

try {
    $response = $client->detectBodyCountAdvance($request, $runtime);
    var_dump($response);
} catch (TeaUnableRetryError $e) {
    var_dump($e->getMessage());
    var_dump($e->getErrorInfo());
    var_dump($e->getLastException());
    var_dump($e->getLastRequest());
}

- The endpoint that you use to upload a file. You can configure an internal endpoint to upload a file over an internal network or a VPC.

Query an endpoint

You can query an endpoint in OpenAPI Explorer.

  1. Select an Alibaba Cloud service on the homepage of OpenAPI Explorer. For example, you can select ECS.

image.png

2. Click the Regions tab.

image.png

3. Find the region that you want to specify and copy the endpoint of the region.

You can also use the following method to query an endpoint:

On the API Debugging tab of OpenAPI Explorer, find the API operation that you want to call and configure the RegionId parameter. OpenAPI Explorer automatically generates SDK sample code from which you can obtain the endpoint.

image.png