tencent cloud

Feedback

Step 2. Create and Test API Service

Last updated: 2022-12-28 16:09:45

    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.
    1. Select the created blogAPI service in the service list to enter the Manage API page.
    2. 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.
    1. 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.
    1. 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.
    2. 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
    1. 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.
    1. 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.

    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 avaliable.

    7x24 Phone Support