Overview
This document describes how to create a service in API Gateway and related API rules, connect them to the SCF function created in step 1, and test them with APIs in the console.
Note:
The API service and function must be in the same region. In this tutorial, the Beijing region is used to create the API service.
Creating API Service and Rule
- Log in to the API Gateway console and select Service on the left sidebar.
- At the top of the Service page, select the Beijing region and click Create to enter the API service creation page.
- In the Create Service pop-up window, set the following parameter information and click Submit.
- Service Name: enter
blogAPI
.
- Access Mode: select Public Network.
- Select the created
blogAPI
service in the service list to enter the Manage API page.
- Click Create to enter the Create API page. In the Frontend Configuration step, refer to the following main parameters to create the API:
- API Name: custom API name.
- Path:
/article
.
- Request Method: GET.
- Authentication Type: select No authentication.
Keep the remaining options as default and click Next.
- In the Backend Configuration step, refer to the following main parameters to create the API:
- Backend Type: select Cloud Function.
- Cloud Function: select the
blogArticle
function created in step 1.
Keep the remaining options as default and click Next.
- Click Complete in Response Result to complete the API creation. Select Test as the Publishing Environment in the pop-up window and click Publish service.
- Click Create on the Manage API tab again to create an API as shown below:
- Path:
/article/{articleId}
.
- Request Method: GET.
- Authentication Type: select No authentication.
- Parameter Configuration: select Add parameter configuration and refer to the following parameters for configuration:
- Parameter Name: articleId
- Parameter Location: Path
- Type: int
- In the Backend Configuration step, refer to the following main parameters to create the API:
- Backend Type: select Cloud Function.
- Cloud Function: select the
blogArticle
function created in step 1.
Keep the remaining options as default and click Next.
- Click Complete in Response Result to complete the API creation. Select Test as the Publishing Environment in the pop-up window and click Publish service.
Debugging API Rules
To debug the API /article
created in step 5 above, click Debug, send a request on the debugging page, and check whether the response body in the returned result is shown as follows:
[{"id": 1, "category": "blog", "title": "hello world", "time": "2017-12-05 13:45"}, {"id": 2, "category": "blog", "title": "record info", "time": "2017-12-06 08:22"}, {"id": 3, "category": "python", "title": "python study", "time": "2017-12-06 18:32"}]
To debug the API /article/{articleId}
created in step 8 above, click API Debug, modify the request parameter value to 1, send a request on the debugging page, and check whether the response body in the returned result is shown as follows:
{"id": 1, "category": "blog", "title": "hello world", "content": "first blog! hello world!", "time": "2017-12-05 13:45"}
Note:
You can also change the value of the request parameter articleId
to another number and check the response content.
Was this page helpful?