tencent cloud

All product documents
Serverless Cloud Function
Step 2. Create and Test API Service
Last updated: 2024-12-02 16:35:35
Step 2. Create and Test API Service
Last updated: 2024-12-02 16:35:35

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

1. Log in to the API Gateway console and select Service on the left sidebar.
2. At the top of the Service page, select the Beijing region and click Create to enter the API service creation page.
3. In the Create Service pop-up window, set the following parameter information and click Submit.
Service Name: enter blogAPI.
Access Mode: select Public Network.
4. Select the created blogAPI service in the service list to enter the Manage API page.
5. 
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.
6. 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.
7. 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.
8. 
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


9. 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.
10. 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

1. 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"}]
2. 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?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback

Contact Us

Contact our sales team or business advisors to help your business.

Technical Support

Open a ticket if you're looking for further assistance. Our Ticket is 7x24 available.

7x24 Phone Support
Hong Kong, China
+852 800 906 020 (Toll Free)
United States
+1 844 606 0804 (Toll Free)
United Kingdom
+44 808 196 4551 (Toll Free)
Canada
+1 888 605 7930 (Toll Free)
Australia
+61 1300 986 386 (Toll Free)
EdgeOne hotline
+852 300 80699
More local hotlines coming soon