All Products
Document Center


Last Updated: Dec 02, 2020

1 Methods to create an API

You can use one of the following methods to create an API:

  • Create an API in the API Gateway console

Log on to the API Gateway console. In the top navigation bar, select a region. In the left-side navigation pane, choose Publish APIs > APIs. On the API List page, click Create API. For more information, see Create an API.

  • Create an API by using OpenAPI Explorer

You can create an API by using OpenAPI Explorer. For more information, see Create an API.

  • Create an API by importing a Swagger file

Swagger is a specification used to describe API definitions. It is widely used to define and describe APIs for backend services. You can import a Swagger 2.0 file to create an API in the API Gateway console. You can use one of the following methods to import a Swagger file:

Use OpenAPI Explorer. For more information, see ImportSwagger.

Perform operations in the API Gateway console. For more information, see Import a Swagger file to create an API.

2 API Gateway instance and API group

2.1 API Gateway instance

An API Gateway instance is composed of a group of resources used to access and process your APIs. The resources include public IP addresses, private IP addresses, public egress IP addresses, and load balancing configurations. API Gateway supports shared instances and dedicated instances. These two types of instances are suitable for different scenarios.

  • Dedicated instances provide high performance and strict service level agreement (SLA) compliance. These instances are suitable for production environments.

  • Shared instances are suitable for development, test, and assessment environments, as well as small-scale production environments.

For more information about the differences between the two types of instances, see Instance type and guidance for selection.

2.2 API group

An API group is a management unit of APIs. Before you create an API, you must create an API group. When you create an API group, the system allocates a second-level domain to the API group. The second-level domain is used only for test. You can use the second-level domain to call APIs from the client. However, you can access this domain for a maximum of 1000 times per day. We recommend that you bind an independent domain that is filed in Alibaba Cloud to your API group. Then, you can use the domain to call APIs in your API group.

For more information about how to bind a domain to an API group, see Bind a wildcard domain name to an API group.

3 Steps to create an API

3.1 Configure basic information

Configure the basic information for the API that you want to create. The information includes Group, API Name, Security Certification, API Options, and Description.

3.2 Define an API request

Define an API request. The detailed configurations include Request Type, Protocol, Custom Domain Name, Request Path, HTTP Method, Request Mode, and Input Parameter Definition.

API Gateway supports the HTTP, HTTPS, and WebSocket protocols.

3.3 Define an API backend service

Define mappings between request and response parameters and configure information of the backend service of your API. The information includes Backend Service Type, Backend Service Address, Backend Request Path, HTTP Method, Backend Timeout, Backend Service Parameter Configuration, Constant Parameter, and System Parameter. Assume that parameter mapping rules are configured for the current API. After API Gateway receives a request for the API, API Gateway maps the request parameters based on the mapping rules before it routes the request to the backend service.

The backend services supported by API Gateway include HTTP (s) Service, Function Compute, VPC, and Mock.

HTTP (s) Service: Create an API with HTTP as the backend service.

Function Compute: Use Function Compute as the backend service of the API.

VPC: Use a resource in a VPC as the backend service of the API.

Mock: Use Mock as the backend service of the API.

3.4 Define response information

Configure Content Type of Response, Sample of Returned Results, Sample of Returned Failure, and Error Code Definition.

4 Configure environments for the API

API Gateway allows you to configure the test (Test), staging (Pre), and production (Release) environments for an API group. This meets your requirement for API calls in different research and development scenarios. For example, in the test environment, the API uses appropriate resources as its backend service. In this way, testers can simulate API calls in the production environment.

For more information, see Configure different environments for an API.