This topic describes how to create an API.
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 . On the APIs 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:
- Call the ImportSwagger operation. For more information, see ImportSwagger.
- Import a Swagger file in the API Gateway console. For more information, see Import Swagger files to create APIs with API Gateway extensions.
API Gateway instance and API group
Instance
An API Gateway instance is 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 serverless 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.
Serverless instances are suitable for development, testing, and assessment environments, as well as small-scale production environments.
For more information about the differences between the two types of instances, see Choose an instance type.
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 name to the API group. This second-level domain name is used for testing. If you use this domain name to make API calls, you can make 100 calls per day in regions outside the Chinese mainland and 1,000 calls per day in regions in the Chinese mainland. We recommend that you bind an independent domain name that is filed in Alibaba Cloud to your API group. Then, you can use the domain name to call APIs in your API group.
For more information about how to bind an independent domain name to an API group, see Make API calls through a custom domain name.
Steps to create an API
Configure basic information
Configure the basic information for the API that you want to create. The information includes Group, API Name, Security Authentication, AppCode Authentication, Signature Algorithm, API Option, and Description.
Define the API request
Define an API request. The detailed configurations include Protocol, Custom Domain Name, Second-level Domain, BasePath, Request Path, HTTP Method, Request Mode, and Request Parameters.
API Gateway supports HTTP and HTTPS for the Protocol parameter.
Define the backend service
Define mappings between the request and response parameters and configure information of the backend service of your API. The information includes Configuration Mode, Backend Service Type, Backend Service, Backend Request Path, HTTP Method, Backend Timeout Period, Backend Service Parameters, Constant Parameters, and System Parameters.
After API Gateway receives a request for the API, API Gateway maps the request parameters based on these configurations before it routes the request to the backend service.
The backend service types supported by API Gateway include HTTP/HTTPS Service, Function Compute, VPC, and Mock.
For information about the HTTP/HTTPS Service type, see Create an API with HTTP as the backend service type.
For information about the Function Compute type, see Use Function Compute as the backend service of the API.
For information about the VPC type, see Use a resource in a VPC as the backend service of an API.
For information about the Mock type, Mock.
Define the response
Define a response from the backend service. Parameters include Response ContentType, Response Example, Error Response Example, and Error Codes.
Environment management
API Gateway allows you to configure the test (Test), staging (Pre), and production (Production) environments for an API group. This meets your requirement for API calls in different scenarios. For example, testing resources are configured for a test environment so that you can test your services by using the APIs with the same API configurations as those in the production environment.
For more information, see Manage environments.