Configure a endpoint

更新时间:
复制 MD 格式

Configure endpoints in Alibaba Cloud Darabonba SDK to route API requests to the correct service domain.

Note

An endpoint is the domain name of an Alibaba Cloud service API. For example, an ECS endpoint can be ecs.cn-hangzhou.aliyuncs.com. Each service has its own endpoints, which may vary by region.

Configure an endpoint to which API requests are sent

Darabonba SDK supports two modes for specifying the API endpoint, listed by priority in descending order:

  1. User-defined endpoint: 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: Specify a region ID, and Darabonba SDK generates an endpoint automatically. This mode works only if the service SDK includes an endpoint data file. Otherwise, the error config.endpoint can not be empty is returned when you initialize the SDK client, and you must specify an exact endpoint. For an example of an endpoint data file, see ECS endpoint data file. If the target region is not in the data file, the endpoint 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

Darabonba SDK supports two endpoints for file uploads.

- The open platform endpoint for authentication. You can configure a VPC endpoint to obtain authentication information over a VPC 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 file upload endpoint. You can configure an internal endpoint to upload files 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 you want to call and set the RegionId parameter. OpenAPI Explorer automatically generates SDK sample code that includes the endpoint.

image.png