All Products
Search
Document Center

API Gateway:Use SDKs to call APIs

Last Updated:Nov 15, 2023

This topic describes how to use 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 Use digest authentication to call an API.

For information about the preparations that you must make before you call an API, see Create an API with a backend service of the HTTP type. An API that you want to call by using an SDK must meet the following conditions:

  • The API uses the Alibaba Cloud App security certification method.

  • The app is authorized before it can call the API.

  • The API is published to a production environment.

1. Download an SDK

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

Method 1 In the left-side navigation pane of the console, choose Call API > Authorized API SDK. On the SDK page, download the SDK that is generated for the app. API Gateway automatically generates SDKs for Objective-C, Android, and Java. For information about SDKs for other programming languages, see the Call Examples in Other Programming Languages (for Reference Only) section on the SDK page.

Method 2 In the left-side navigation pane of the console, choose OpenAPI > SDKs. On the SDK page, download the SDK that is generated for the API group. API Gateway automatically generates SDKs for Objective-C, Android, Java, Golang, and TypeScript.

2. Use the SDK to call the API

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

SDK directory
  • sdk folder

* sdk/{{regionId}} `The SDK for Java folder. The folder 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 `The core package of the SDK. The core package 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 information about how to use an SDK, 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, see Troubleshoot issues that occur during API debugging.

Requestid