Endpoint configuration

更新时间:
复制 MD 格式

This topic describes the endpoint configuration for the upgraded 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.

Endpoint Settings

Darabonba SDK lets you 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

    You can search for the product homepage in the OpenAPI Developer Portal. For more information, see the end of this document. TypeScript version:

    import * as $OpenApi from '@alicloud/openapi-client';
    
    export default class Client {
      static async main(): Promise<void> {
        const config = new $OpenApi.Config({
          // Omit the credential configuration.
          // The endpoint that you want to specify.
          endpoint: 'Endpoint'
        });
      }
    }

    JavaScript:

    const { Config } = require('@alicloud/openapi-client');
    
    async function main() {
      const config = new Config({
        // Omit the credential configuration.
        // The endpoint that you want to specify.
        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. The following sample code provides an example on how to specify a concatenated endpoint in TypeScript:

import * as $OpenApi from '@alicloud/openapi-client';

export default class Client {
  static async main(): Promise<void> {
    const config = new $OpenApi.Config({
      // Omit the credential configuration.
      // The region that you want to access.
      regionId: 'RegionId'
    });
  }
}

JavaScript:

const { default: Ecs20140526 } = require('@alicloud/ecs20140526');
const { Config } = require('@alicloud/openapi-client');
async function main() {
  const config = new Config({
    // Omit the credential configuration.
    // The region that you want to access.
    regionId: 'RegionId'
  });
}

File Upload Endpoint

The upgraded SDK supports two Endpoint configurations for file uploads:

  • 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. The following sample code provides an example on how to configure the endpoint of an open platform in TypeScript:

    import Facebody20191230, * as $Facebody20191230 from '@alicloud/facebody20191230';
    import * as $OpenApi from '@alicloud/openapi-client';
    import * as $Util from '@alicloud/tea-util';
    import { createReadStream } from 'fs';
    
    export default class Client {
      static async main(): Promise<void> {
        const config = new $OpenApi.Config({
          // Omit the credential configuration.
          // The region that you want to access.
          regionId: 'RegionId',
          // The endpoint of the open platform.
          openPlatformEndpoint: 'openplatform-vpc.cn-shanghai.aliyuncs.com'
        });
        const client = new Facebody20191230(config);
        const request = new $Facebody20191230.DetectBodyCountAdvanceRequest({
          imageURLObject: createReadStream("The directory of the file that you want to upload on your computer"),
        });
        // Create a RuntimeObject instance and configure runtime parameters. 
        const runtime = new $Util.RuntimeOptions({});
        const resp = await client.DetectBodyCountAdvance(request, runtime);
        console.log(resp.headers);
        console.log(resp.body);
      }
    }

    JavaScript version:

    const { default: Facebody20191230, DetectBodyCountAdvanceRequest } = require('@alicloud/facebody20191230');
    const { Config } = require('@alicloud/openapi-client');
    const { RuntimeOptions } = require('@alicloud/tea-util');
    const { createReadStream } = require('fs');
    
    async function main() {
      const config = new Config({
        // Omit the credential configuration.
        // The region to access.
        regionId: 'RegionId',
        // Set the authentication URL.
        openPlatformEndpoint: 'openplatform-vpc.cn-shanghai.aliyuncs.com',
      });
      const client = new Facebody20191230(config);
      const request = new DetectBodyCountAdvanceRequest({
        imageURLObject: createReadStream("path/to/local/file"),
      });
      // Create a RuntimeObject instance and set runtime parameters.
      const runtime = new RuntimeOptions({});
      const resp = await client.DetectBodyCountAdvance(request, runtime);
      console.log(resp.headers);
      console.log(resp.body);
    }
  • The address for file uploads. In a VPC or an internal network, you can use an internal network address to upload files. TypeScript:

    import Facebody20191230, * as $Facebody20191230 from '@alicloud/facebody20191230';
    import * as $OpenApi from '@alicloud/openapi-client';
    import * as $Util from '@alicloud/tea-util';
    import { createReadStream } from 'fs';
    
    export default class Client {
      static async main(): Promise<void> {
        const config = new $OpenApi.Config({
          // Omit the credential configuration.
          // The region that you want to access.
          regionId: 'RegionId',
          // The endpoint of the open platform.
          openPlatformEndpoint: 'openplatform-vpc.cn-shanghai.aliyuncs.com',
          // The OSS endpoint that you want to use to upload the file. If you set the endpoint type to internal, you can use an internal endpoint to upload the file to OSS over a VPC or the classic network. If you set the endpoint type to accelerate, you can use an accelerated endpoint outside China to upload the file to OSS.
          endpointType: 'internal'
        });
        const client = new Facebody20191230(config);
        const request = new $Facebody20191230.DetectBodyCountAdvanceRequest({
          imageURLObject: createReadStream("The directory of the file that you want to upload on your computer"),
        });
        // Create a RuntimeObject instance and configure runtime parameters. 
        const runtime = new $Util.RuntimeOptions({});
        const resp = await client.DetectBodyCountAdvance(request, runtime);
        console.log(resp.headers);
        console.log(resp.body);
      }
    }

    JavaScript version:

    const { default: Facebody20191230, DetectBodyCountAdvanceRequest } = require('@alicloud/facebody20191230');
    const { Config } = require('@alicloud/openapi-client');
    const { RuntimeOptions } = require('@alicloud/tea-util');
    const { createReadStream } = require('fs');
    async function main() {
      const config = new Config({
        // Omit the credential configuration.
        // The region to access.
        regionId: 'RegionId',
        // Set the authentication URL.
        openPlatformEndpoint: 'openplatform-vpc.cn-shanghai.aliyuncs.com',
        // Set the OSS upload URL. 'internal' is for VPC and classic network. 'accelerate' is for accelerated domain names outside China.
        endpointType: 'internal'
      });
      const client = new Facebody20191230(config);
      const request = new DetectBodyCountAdvanceRequest({
        imageURLObject: createReadStream("path/to/local/file"),
      });
      // Create a RuntimeObject instance and set runtime parameters.
      const runtime = new RuntimeOptions({});
      const resp = await client.DetectBodyCountAdvance(request, runtime);
      console.log(resp.headers);
      console.log(resp.body);
    }

Appendix: Finding endpoints

You can find product endpoints on the Developer Portal:

  1. To open a cloud product homepage, select a cloud product, such as ECS, from the home page:

image.png

2. Locate the Service Region list:

image.png

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

You can also search in the following ways:

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