Cloud-native API Gateway lets you create APIs either within or outside an instance. You can create APIs in the console or by importing an OpenAPI file. This topic describes how to create a REST API and add an operation.
Scenarios
The two methods for creating APIs, within and outside an instance, apply to the following scenarios:
Create an API within an instance
Dedicated resource management: The API is used exclusively within a specific instance to manage specific resources or internal logic.
Security and isolation: Data or features require strict isolation for security and are called only from within the instance.
Simplified service configuration: This method simplifies API configuration and management within a specific instance.
Create an API outside an instance
Cross-instance shared access: Multiple instances can share API definition information.
Centralized management and monitoring: This method provides unified access control, log recording, and traffic management.
Create a REST API in the console
Cloud-native API Gateway supports two methods for creating APIs: within an instance and outside of it.
API outside an instance
Log on to the Cloud-native API Gateway console.
In the navigation pane on the left, click API. In the top menu bar, select a region.
Click Create API.
On the REST API card, click Create. In the Create REST API panel, configure the parameters and click Confirm.
Configuration item
Description
API Name
Enter a custom name for the API. The API name must be globally unique.
Base Path
The base path of the API. When you access a specific operation, the full path is
http(s)://{Domain Name}/{BasePath}/{Operation Path}.Version Management
Specifies whether to enable API version management. APIs of different versions are treated as independent APIs. They share the same API name but can have different basic information and operation details. You must specify a version identifier to access a specific version.
If you enable Version Management, you must configure Usage Method.
NoteIf you set Usage Method to Query, you must configure the Add Query parameter.
If you set Usage Method to Header, you must configure the Add Header parameter.
Usage Method
Supports Path, Query, and Header.
If you use Path, the full access path is /API Base Path/Version Number/Operation Path.
If you use Query, the full access path is /API Base Path/Operation Path. In the request parameters, you must set the Add Query parameter to the version number.
If you use Header, the full access path is /API Base Path/Operation Path. In the request header, you must set the Add Header parameter to the version number.
Description
Enter a description for the API.
Resource Group
Select the target resource group. You can click Create Resource Group on the right.
Click Create API.
On the REST API card, click Create. In the Create REST API panel, configure the parameters and click Confirm.
Configuration item
Description
API Name
Enter a custom name for the API. The API name must be globally unique.
Base Path
The base path of the API. When you access a specific operation, the full path is
http(s)://{Domain Name}/{BasePath}/{Operation Path}.Version Management
Specifies whether to enable API version management. APIs of different versions are treated as independent APIs. They share the same API name but can have different basic information and operation details. You must specify a version identifier to access a specific version.
If you enable Version Management, you must configure Usage Method.
NoteIf you set Usage Method to Query, you must configure the Add Query parameter.
If you set Usage Method to Header, you must configure the Add Header parameter.
Usage Method
Supports Path, Query, and Header.
If you use Path, the full access path is /API Base Path/Version Number/Operation Path.
If you use Query, the full access path is /API Base Path/Operation Path. In the request parameters, you must set the Add Query parameter to the version number.
If you use Header, the full access path is /API Base Path/Operation Path. In the request header, you must set the Add Header parameter to the version number.
Description
Enter a description for the API.
Resource Group
Select the target resource group. You can click Create Resource Group on the right.
API within an instance
Log on to the Cloud-native API Gateway console.
In the navigation pane on the left, click Instances. In the top menu bar, select a region.
On the Instances page, click the target Instance ID to go to the Overview page. Then, in the navigation pane on the left, click API and click Create API.
On the REST API card, click Create. In the Create REST API panel, configure the parameters and click Confirm.
Configuration item
Description
API Name
Enter a custom name for the API. The API name must be globally unique.
Domain Names
Select the domain names for the API. You can select multiple domain names.
To create a new domain name, click Add Domain Name.
Base Path
The base path of the API. When you access a specific operation, the full path is
http(s)://{Domain Name}/{BasePath}/{Operation Path}.Version Management
Specifies whether to enable API version management. APIs of different versions are treated as independent APIs. They share the same API name but can have different basic information and operation details. You must specify a version identifier to access a specific version.
If you enable Version Management, you must configure Usage Method.
NoteIf you set Usage Method to Query, you must configure the Add Query parameter.
If you set Usage Method to Header, you must configure the Add Header parameter.
Usage Method
Supports Path, Query, and Header.
If you use Path, the full access path is /API Base Path/Version Number/Operation Path.
If you use Query, the full access path is /API Base Path/Operation Path. In the request parameters, you must set the Add Query parameter to the version number.
If you use Header, the full access path is /API Base Path/Operation Path. In the request header, you must set the Add Header parameter to the version number.
Description
Enter a description for the API.
Resource Group
Select the target resource group. You can click Create Resource Group on the right.
Scenario
Select the scenario for the current operation.
Basic scenario: Single Service.
Grayscale scenarios: By Ratio (Multi-service), By Content (Multi-service), Tag-based Routing (By Ratio).
NoteThe sum of traffic proportions for all target services with weights must be 100%.
Backend Service
Associate a backend service under this gateway or VPC. If no backend service exists under the gateway, click Create Service to create one.
ImportantWhen you create a new service, the service port information might not appear immediately. You need to expand the Service Name drop-down list and click Refresh. Because the port information is synchronized asynchronously, it may take a moment to load and display the complete service port information.
Create a REST API by importing an OpenAPI file
Cloud-native API Gateway lets you create APIs in two ways: on a specific instance or independent of an instance.
API outside an instance
Log on to the Cloud-native API Gateway console.
In the navigation pane on the left, click API. In the top menu bar, select a region.
Click Create API.
On the REST API card, click Import. In the Create From OpenAPI panel, configure the parameters and click Dry Run And Create.
Configuration item
Description
API Name
Enter a custom name for the API. The API name must be globally unique.
Upload Method
Supports Local File and Import From OSS.
NoteFiles for both local upload and OSS import must comply with the OpenAPI specification.
OpenAPI File
This parameter is configured when you select Local File. You can select a file or paste text content. The file size is limited to 30 MB.
Select Region
This parameter is configured when you select Import from OSS. Select a region to choose its OSS resources.
OSS Bucket
This parameter is configured when you select Import from OSS. Select an OSS bucket. Buckets without region attributes are not supported.
Version Management
Specifies whether to enable API version management. APIs of different versions are treated as independent APIs. They share the same API name but can have different basic information and operation details. You must specify a version identifier to access a specific version.
If you enable Version Management, you must configure Usage Method.
NoteIf you set Usage Method to Query, you must configure the Add Query parameter.
If you set Usage Method to Header, you must configure the Add Header parameter.
Usage Method
Supports Path, Query, and Header.
If you use Path, the full access path is /API Base Path/Version Number/Operation Path.
If you use Query, the full access path is /API Base Path/Operation Path. In the request parameters, you must set the Add Query parameter to the version number.
If you use Header, the full access path is /API Base Path/Operation Path. In the request header, you must set the Add Header parameter to the version number.
Description
Enter a description for the API.
Resource Group
Select the target resource group. You can click Create Resource Group on the right.
API within an instance
Log on to the Cloud-native API Gateway console.
In the navigation pane on the left, click Instances. In the top menu bar, select a region.
On the Instances page, click the target Instance ID to go to the Overview page. Then, in the navigation pane on the left, click API and click Create API.
On the REST API card, click Import. In the Create From OpenAPI panel, configure the parameters and click Dry Run And Create.
Configuration item
Description
API Name
Enter a custom name for the API. The API name must be globally unique.
Domain Names
Select the domain names for the API. You can select multiple domain names.
To create a new domain name, click Add Domain Name.
Upload Method
Supports Local File and Import From OSS.
NoteFiles for both local upload and OSS import must comply with the OpenAPI specification.
OpenAPI File
This parameter is configured when you select Local File. You can select a file or paste text content. The file size is limited to 30 MB.
Select Region
This parameter is configured when you select Import from OSS. Select a region to choose its OSS resources.
OSS Bucket
This parameter is configured when you select Import from OSS. Select an OSS bucket. Buckets without region attributes are not supported.
Version Management
Specifies whether to enable API version management. APIs of different versions are treated as independent APIs. They share the same API name but can have different basic information and operation details. You must specify a version identifier to access a specific version.
If you enable Version Management, you must configure Usage Method.
NoteIf you set Usage Method to Query, you must configure the Add Query parameter.
If you set Usage Method to Header, you must configure the Add Header parameter.
Usage Method
Supports Path, Query, and Header.
If you use Path, the full access path is /API Base Path/Version Number/Operation Path.
If you use Query, the full access path is /API Base Path/Operation Path. In the request parameters, you must set the Add Query parameter to the version number.
If you use Header, the full access path is /API Base Path/Operation Path. In the request header, you must set the Add Header parameter to the version number.
Description
Enter a description for the API.
Resource Group
Select the target resource group. You can click Create Resource Group on the right.
Scenario
Select the scenario for the current operation.
Basic scenario: Single Service.
Grayscale scenarios: By Ratio (Multi-service), By Content (Multi-service), Tag-based Routing (By Ratio).
NoteThe sum of traffic proportions for all target services with weights must be 100%.
Backend Service
Associate a backend service under this gateway or VPC. If no backend service exists under the gateway, click Create Service to create one.
ImportantWhen you create a new service, the service port information might not appear immediately. You need to expand the Service Name drop-down list and click Refresh. Because the port information is synchronized asynchronously, it may take a moment to load and display the complete service port information.
Add an operation
On the details page of the REST API, click Add Operation.
In the Create Operation panel, configure the parameters and click Add.
Configuration item
Description
Operation Name
Enter a custom name for the operation. The name must be globally unique within the API.
Operation Path
The specific path of the operation.
Method
The request method of the operation. The combination of the operation path and method must be globally unique within the API.
Description
Description of the interface.
Request Definition
You can define Header, Query, and Parameter Path parameters, along with the Body parameter.
Path parameters support three ways to define variables in the operation path:
/books/{bookId}
/books/[bookId]
/books/:bookId
Use the {bookId} format.
NoteRequest definitions are used only to generate SDKs and documents. They are not validated at runtime.
Response Definition
Define the data structure for different response codes.
Response code definitions are used only to generate documents. They are not validated at runtime.
Mock
Mock configurations take effect only when the API is published in a mock scenario.
NoteThe mock configuration feature for REST APIs is supported for APIs outside an instance. It is not supported for APIs within an instance.
Consumer Authentication
Enable or disable consumer authentication. This feature is disabled by default. If you enable consumer authentication, you must attach a consumer authorization to the current operation. Otherwise, the operation cannot be accessed.