This topic describes how to manage REST APIs through the console, including key operations such as publishing, importing, exporting, and unpublishing APIs. You can also generate SDKs and their documentation with one click in the console, which helps you efficiently manage and integrate APIs, improving the convenience of the development process.
Publish an API
Prerequisites
Before publishing an API, you need to define and create operations in the API.
Procedure
Cloud-native API Gateway supports publishing two types of APIs: shared API and instance-scoped API.
Shared API
Log on to the Cloud-native API Gateway console. In the left-side navigation pane, select API, and select a region in the top menu bar.
Click the target API. Click Publish in the upper-right corner.
In the Publish API panel, configure the related parameters, and then click Publish.
Configuration item
Description
Domain Name
Select a domain name to publish the API. The published API can be accessed by using the domain name.
If no domain name is available, you can click Add Domain Name. For more information, see Create a domain name.
Instance
Select the created Cloud-native API Gateway instance. Different business environments can be distinguished by different instances to implement API publishing in multiple environments.
Scenarios
Scenarios include basic scenarios and grayscale scenarios. For more information about different types of target services, see Routing.
Basic scenario
Mock: The response of the operation returns the mock configuration in the operation definition. If the operation does not have a mock configuration defined, the operation cannot be accessed.
NoteIf you want to publish an API to the Mock scenario, you must make sure that a mocked response is configured for at least one operation in the API. Otherwise, the API fails to be published.
Single Service: All traffic requests are forwarded to a specific backend service (the most commonly used scenario).
Canary release scenario
By Percentage (Multi-service): All traffic is distributed to the corresponding backend services in proportion, commonly used in traffic switching and phased release scenarios.
NoteThe weights of all services must sum up to 100.
By Content (Multi-service): All traffic is distributed to the corresponding backend services according to the matching conditions. If the Default option is selected for a matching condition, traffic will enter the backend service corresponding to that entry when no other matching rules are hit.
The following match condition types are supported: equal to, prefix, and regular expression.
Supported parameter types: Query and Header.
The "and" operation logic is used between multiple match conditions.
ImportantOnly one entry can have the Default option selected, and the matching conditions for the remaining entries cannot be empty.
By Tag (Propotion-based Rounting): In the tag-based routing scenario, all traffic is distributed proportionally to multiple versions of multiple backend services. In the end-to-end grayscale scenario, it is recommended to use single service routing first to obtain better performance and experience.
Backend Services
Associate the backend service under the gateway/VPC. If there is no backend service under the gateway, you can click Create Service. For more information, see Create services.
Publication Description
Enter a description for the published API.
Instance-scoped API
Log on to the Cloud-native API Gateway console. In the left-side navigation pane, select Instance, and select a region in the top menu bar.
On the Instance page, click the ID of the target gateway instance. In the left-side navigation pane, select API, and click the target API.
Click Publish in the upper-right corner. In the Publish API panel, configure the related parameters, and then click Publish.
Configuration item
Description
Instance
The created Cloud-native API Gateway instance. Different business environments can be distinguished by different instances to implement API publishing in multiple environments.
VPC
The VPC to which the instance operation belongs.
Publication Scope
The publication scope of the API-level operation. You can select the operation name to view the details of the affected operations.
Description
Enter a description for the published API.
Add an API version
Currently, only APIs created outside an instance support version addition.
Log on to the Cloud-native API Gateway console. In the left-side navigation pane, select API, and select a region in the top menu bar.
Click the target API, and click in the upper-right corner. Complete the related configurations:
Configuration item
Description
Usage
Supports three methods: Path, Query, and Header.
NoteWhen you select Usage as Query, you need to configure the parameter Add Query.
When you select Usage as Header, you need to configure the parameter Add Header.
When using Path, the complete access path needs to be: /API base path/version number/operation path.
When using Query, the complete access path is: /API base path/operation path, and the request parameter needs to configure the parameter Add Query as the version number.
When using Header, the complete access path is: /API base path/operation path, and the request header needs to configure the parameter Add Header as the version number.
(Optional) After adding, you can click Version at the top of the page to switch versions.
View historical versions
The publication history retains the last 10 records.
Cloud-native API Gateway provides two ways to view historical versions: outside an instance and inside an instance:
Shared API
Log on to the Cloud-native API Gateway console. In the left-side navigation pane, select API, and select a region in the top menu bar.
Click the target API, and then click the Publish History tab.
Instance-scoped API
Log on to the Cloud-native API Gateway console. In the left-side navigation pane, select Instance, and select a region in the top menu bar.
On the Instance page, click the ID of the target gateway instance. In the left-side navigation pane, select API, click the target API, and then click the Publish History tab.
Click View in the Actions column of the target historical version to view the details of the historical version.
Generate SDKs and documentation
Cloud-native API Gateway provides two ways to generate SDKs and documentation: outside an instance and inside an instance:
Shared API
Log on to the Cloud-native API Gateway console. In the left-side navigation pane, select API, and select a region in the top menu bar.
Click the target API. Click in the upper-right corner.
Instance-scoped API
Log on to the Cloud-native API Gateway console. In the left-side navigation pane, select Instance, and select a region in the top menu bar.
On the Instance page, click the ID of the target gateway instance. In the left-side navigation pane, select API, and click the target API.
Click in the upper-right corner.
In the Generate SDK & Documentation dialog box, configure the related parameters, and then click Generate And Download.
Configuration item
Description
Version
Select the version of the API for which you want to generate the SDK and documentation.
NoteAPIs created inside an instance do not have version management capability, so this option is not available.
For APIs created outside an instance, you can choose whether to enable API version management capability. If version management was not enabled when creating the API, this option is not available.
Language
Select the language in which you want to generate the SDK. Valid values: Java, Golang, Python, Node.js, TypeScript, and Swift.
Wait until the SDK and documentation are generated and automatically downloaded. They are automatically downloaded as a compressed package to your local computer. Then, go to the download path of the browser to view the package.
NoteAfter extracting, you can refer to the
README.mddocument as a guide for using the SDK. This document contains the basic information needed to use the SDK.
Import APIs
Cloud-native API Gateway provides two ways to import APIs: outside an instance and inside an instance:
Shared API
Log on to the Cloud-native API Gateway console. In the left-side navigation pane, select API, and select a region in the top menu bar.
Click the target API. Click in the upper-right corner.
Instance-scoped API
Log on to the Cloud-native API Gateway console. In the left-side navigation pane, select Instance, and select a region in the top menu bar.
On the Instance page, click the ID of the target gateway instance. In the left-side navigation pane, select API, and click the target API.
Click in the upper-right corner.
In the Create File Based On OpenAPI panel, configure the related parameters, and then click Dry Run And Create.
Export APIs
Cloud-native API Gateway provides two ways to export APIs: outside an instance and inside an instance:
Shared API
Log on to the Cloud-native API Gateway console. In the left-side navigation pane, select API, and select a region in the top menu bar.
Click the target API. Click in the upper-right corner.
Instance-scoped API
Log on to the Cloud-native API Gateway console. In the left-side navigation pane, select Instance, and select a region in the top menu bar.
On the Instance page, click the ID of the target gateway instance. In the left-side navigation pane, select API, and click the target API.
Click in the upper-right corner.
In the Export dialog box, click Confirm. The browser will download the API to the default download path on your local computer.
Unpublish an API
After unpublishing, all related domain names will not be able to access the operations under the API. Although the API instance will stop processing requests, its configuration and history will still be retained in the system. Please perform this operation with caution.
Cloud-native API Gateway provides two ways to unpublish APIs: outside an instance and inside an instance:
Shared API
Log on to the Cloud-native API Gateway console. In the left-side navigation pane, select API, and select a region in the top menu bar.
Click the target API. Click in the upper-right corner.
Instance-scoped API
Log on to the Cloud-native API Gateway console. In the left-side navigation pane, select Instance, and select a region in the top menu bar.
On the Instance page, click the ID of the target gateway instance. In the left-side navigation pane, select API, and click the target API.
Click in the upper-right corner.
In the Confirm Unpublishing dialog box, click Unpublish.
Delete an API
If the current API has published instances, all instances need to be unpublished before the deletion operation.
Deleting an API will completely remove the API's configuration, documentation, and history, and cannot be recovered. Please perform this operation with caution.
Cloud-native API Gateway provides two ways to delete APIs: outside an instance and inside an instance:
Shared API
Log on to the Cloud-native API Gateway console. In the left-side navigation pane, select API, and select a region in the top menu bar.
Click the target API. Click in the upper-right corner.
Instance-scoped API
Log on to the Cloud-native API Gateway console. In the left-side navigation pane, select Instance, and select a region in the top menu bar.
On the Instance page, click the ID of the target gateway instance. In the left-side navigation pane, select API, and click the target API.
Click in the upper-right corner.
In the dialog box that appears, click Delete.