Step 2. Create and Test API Service

Last updated: 2020-02-27 13:12:37

Scenario

In this section, you will create a service in the API gateway and the associated API rules, which will be docked in the Step one The SCF cloud function created in the, and passed the API test in the console to test the correctness of API.

The API service and function must be in the same region. In this tutorial, you will use the Beijing area to create a API service.

Create API services and rules

  1. Login Tencent Cloud Console Select "Tencent Cloud services"-> "Middleware"-> "API Gateway" at the top of the page to enter the "API Gateway" overview page.

  2. Select "Service" in Left sidebar, and change the region to "Beijing" at the top of the "Service" page.

  3. On the Services page, click the [Create] button to serve Create API. as shown below:

  4. In the pop-up "Create Service" window, write the service name blogAPI And click "submit" to create.

  5. After completing the service creation, enter the created blogAPI Service, select the "manage API" tab. as shown below:

  6. Click [Create] to enter the "Create API" page. In the "frontend configuration" step, refer to the following main parameter information to create a API:.

  • API Name : custom API name.
  • The path is /article
  • Request method : GET .
  • Authentication Type For the convenience of later testing, select [exemption from authentication]
    Please keep the default settings for the rest of the configuration, and click "next".
  1. In the "backend configuration" step, refer to the following main parameter information to create a API:
  • Backend Type Select [cloud function].
  • Serverless Cloud Function The selection function is Step one Has been created in the blogArticle Function.
    Please keep the default values for the rest of the settings, and click "next".
  1. Click finish in the response result to complete the creation of the API.
  2. Click New In the API Management Tab to create another API with the path of /article/{articleId} And the request method of GET. select No Authentication , and enter the parameter articleId In the parameter configuration with Path as the parameter location, int as the parameter type, and 1 as the default value, and then click Next .
  3. The backend type is selected as [cloud function], and the selection function is Step one Has been created in the blogArticle Function, click next.
  4. Click finish in the response result to complete the creation of the API.

Debug API rules

  1. To debug the API /article Created in the step 5 above, click API Debugging , send a request in the debugging page, and check whether the response body in the returned result is shown as follows:
[{"category": "blog", "time": "2017-12-05 13:45", "id": 1, "title": "hello world"}, {"category": "blog", "time": "2017-12-06 08:22", "id": 2, "title": "record info"}, {"category": "python", "time": "2017-12-06 18:32", "id": 3, "title": "python study"}]
  1. To debug the API /article/{articleId} Created in the step 7 above, click API Debugging , modify the request parameter value to 1 and send a request in the debugging page, and check whether the response body in the returned result is shown as follows:
{"category": "blog", "content": "first blog! hello world!", "time": "2017-12-05 13:45", "id": 1, "title": "hello world"}
  1. It can also be modified. Step 2 The value of the request parameter articleId in is another number to view the content of the response.

Was this page helpful?

Was this page helpful?

  • Not at all
  • Not very helpful
  • Somewhat helpful
  • Very helpful
  • Extremely helpful
Send Feedback
Help