All Products
Search
Document Center

Use SDKs to call APIs

Last Updated: Dec 21, 2020

This topic describes how to use the SDKs that are automatically generated in API Gateway to call published APIs in your business system.

Overview

The SDKs that are automatically generated in API Gateway are integrated with a signature mechanism. By using the signature mechanism, you do not need to calculate a signature. If you want to calculate a signature on the client, see Request signature.

For information about the preparations made to call APIs, see Create an API operation with HTTP as the backend service. The APIs that you want to call by using SDKs must meet the following conditions:

  • The APIs use one of the following security certification methods: Alibaba Cloud APP and OpenID Connect & Alibaba Cloud APP.

  • Apps are authorized before they can call the APIs.

  • The APIs are published to a Release environment.

1. Download SDKs

You can use one of the following methods to download SDKs in the API Gateway console:

1.1 In the left-side navigation pane of the console, choose Consume APIs > Authorized APIs SDK. On the Authorized APIs SDK Auto-Generation page, download the app-specific SDKs that are used to call APIs. API Gateway automatically generates SDKs for Objective-C, Android, and Java. For information about SDKs for other languages, see the Other Language Example section on the Authorized APIs SDK Auto-Generation page.

Download SDKs

1.2 In the left-side navigation pane of the console, choose Publish APIs > Owned APIs SDK. On the Owned APIs SDK Auto-Generation page, download API group-specific SDKs. API Gateway automatically generates SDKs for Objective-C, Android, Java, Golang, and TypeScript.

Download SDKs that are automatically generated

2. Use SDKs to call APIs

The following figure shows the directory structure of a decompressed SDK package that you downloaded in the API Gateway console.

SDK directory
  • sdk folder

* sdk/{{regionId}} `SDK for Java folder, which contains the code to call all APIs in each group.`

* HttpApiClient{{group}}.java `Describes how to call APIs in a specific group over HTTP.`

* HttpsApiClient{{group}}.java `Describes how to call APIs in a specific group over HTTPS.`

* WebSocketApiClient{{group}}.java `Describes how to call APIs in a specific group over WebSocket.`

* Demo{{group}}.java `Contains the sample code of all API calls in a specific group.`

  • doc/{{regionId}} folder

* ApiDocument_{{group}}.md `Indicates the API documentation in a specific group.`

  • lib folder

* sdk-core-java-1.1.5.jar `Core package, which is the dependency of the SDK.`

* sdk-core-java-1.1.5-sources.jar `Source code of the dependency.`

* sdk-core-java-1.1.5-javadoc.jar `JAR file of the core package.`

Readme.md `User guide of the SDK.`

LICENSE `License`

For more information about how to use SDKs, see Readme.md.

Note: AppKey and AppSecret are used to authenticate user requests in API Gateway. If AppKey and AppSecret are stored on the client, encrypt them.

3. Troubleshooting

If an error occurs when you use an SDK to call an API, you can obtain the request ID from the X-Ca-Request-Id header and troubleshoot the issue. For more information about troubleshooting, see Troubleshooting.

Requestid