24
API Gateway Best Practices Issue 01 Date 2020-06-02 HUAWEI TECHNOLOGIES CO., LTD.

Best Practices - support.huaweicloud.com · API Gateway Best Practices Issue 01 Date 2020-06-02 HUAWEI TECHNOLOGIES CO., LTD

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Best Practices - support.huaweicloud.com · API Gateway Best Practices Issue 01 Date 2020-06-02 HUAWEI TECHNOLOGIES CO., LTD

API Gateway

Best Practices

Issue 01

Date 2020-06-02

HUAWEI TECHNOLOGIES CO., LTD.

Page 2: Best Practices - support.huaweicloud.com · API Gateway Best Practices Issue 01 Date 2020-06-02 HUAWEI TECHNOLOGIES CO., LTD

Copyright © Huawei Technologies Co., Ltd. 2020. All rights reserved.

No part of this document may be reproduced or transmitted in any form or by any means without priorwritten consent of Huawei Technologies Co., Ltd. Trademarks and Permissions

and other Huawei trademarks are trademarks of Huawei Technologies Co., Ltd.All other trademarks and trade names mentioned in this document are the property of their respectiveholders. NoticeThe purchased products, services and features are stipulated by the contract made between Huawei andthe customer. All or part of the products, services and features described in this document may not bewithin the purchase scope or the usage scope. Unless otherwise specified in the contract, all statements,information, and recommendations in this document are provided "AS IS" without warranties, guaranteesor representations of any kind, either express or implied.

The information in this document is subject to change without notice. Every effort has been made in thepreparation of this document to ensure accuracy of the contents, but all statements, information, andrecommendations in this document do not constitute a warranty of any kind, express or implied.

Issue 01 (2020-06-02) Copyright © Huawei Technologies Co., Ltd. i

Page 3: Best Practices - support.huaweicloud.com · API Gateway Best Practices Issue 01 Date 2020-06-02 HUAWEI TECHNOLOGIES CO., LTD

Contents

1 Querying Mobile Number Home Locations...................................................................... 1

2 Opening Huawei Cloud Service Instances.......................................................................11

API GatewayBest Practices Contents

Issue 01 (2020-06-02) Copyright © Huawei Technologies Co., Ltd. ii

Page 4: Best Practices - support.huaweicloud.com · API Gateway Best Practices Issue 01 Date 2020-06-02 HUAWEI TECHNOLOGIES CO., LTD

1 Querying Mobile Number HomeLocations

Overview

The best practice for HUAWEI CLOUD API Gateway guides you through APIopening and calling.

This chapter provides guidance on opening a mobile number location lookupservice API and publishing the API in the RELEASE environment. It also presentsinstructions on binding a request throttling policy to the API to ensure continuous,stable API services.

What Is API Gateway?

API Gateway is a high-performance, high-availability, and high-security APIhosting service that helps enterprises build, manage, and deploy APIs at any scale.

What You Can Do with API Gateway

● Easily create, manage, and deploy APIs at any scale.● Configure flexible request throttling policies to ensure continuous, stable API

services.● Monitor API services in terms of multiple metrics.

Preparing the Environment

Before using API Gateway to open the mobile number location lookup service,obtain a username and password for logging in to the HUAWEI CLOUD console,and ensure that the username has completed real-name authentication. Thencollect the required information according to Table 1-1.

Table 1-1 Environment information

Item Example

API group name PhoneNumberGroup

API GatewayBest Practices 1 Querying Mobile Number Home Locations

Issue 01 (2020-06-02) Copyright © Huawei Technologies Co., Ltd. 1

Page 5: Best Practices - support.huaweicloud.com · API Gateway Best Practices Issue 01 Date 2020-06-02 HUAWEI TECHNOLOGIES CO., LTD

Item Example

API name PhoneNumber

Authentication mode None

Request path /test/{phoneNumber}

Backend address apigdemo.myhuaweicloud.com

Backend request path /api/mobile/{phoneNumber}

Environment RELEASE

Request throttlingpolicy name

PhoneNumberThrottling

Throttling period 1 minute

Maximum API requests 20

Maximum userrequests

10

Opening an API

Step 1 Log in to the HUAWEI CLOUD management console, select a region in the upperleft corner, and choose Service List > Application > API Gateway.

Step 2 Create an API group.

API GatewayBest Practices 1 Querying Mobile Number Home Locations

Issue 01 (2020-06-02) Copyright © Huawei Technologies Co., Ltd. 2

Page 6: Best Practices - support.huaweicloud.com · API Gateway Best Practices Issue 01 Date 2020-06-02 HUAWEI TECHNOLOGIES CO., LTD

Figure 1-1 Creating an API group

Figure 1-2 Prompt message

Step 3 Create an API.

1. Set the basic information of the API, as shown in Figure 1-4.For details, see the User Guide.

API GatewayBest Practices 1 Querying Mobile Number Home Locations

Issue 01 (2020-06-02) Copyright © Huawei Technologies Co., Ltd. 3

Page 7: Best Practices - support.huaweicloud.com · API Gateway Best Practices Issue 01 Date 2020-06-02 HUAWEI TECHNOLOGIES CO., LTD

Figure 1-3 API list page

Figure 1-4 Setting basic API information

2. On the Define API Request page, set the API request information.For details, see the User Guide.

API GatewayBest Practices 1 Querying Mobile Number Home Locations

Issue 01 (2020-06-02) Copyright © Huawei Technologies Co., Ltd. 4

Page 8: Best Practices - support.huaweicloud.com · API Gateway Best Practices Issue 01 Date 2020-06-02 HUAWEI TECHNOLOGIES CO., LTD

3. On the Define Backend Request page, set the backend request information.For details, see the User Guide.

4. On the Define Response page, set the example success response.

API GatewayBest Practices 1 Querying Mobile Number Home Locations

Issue 01 (2020-06-02) Copyright © Huawei Technologies Co., Ltd. 5

Page 9: Best Practices - support.huaweicloud.com · API Gateway Best Practices Issue 01 Date 2020-06-02 HUAWEI TECHNOLOGIES CO., LTD

5. Click Finish.

Step 4 Debug the API.

Figure 1-5 API list page

Figure 1-6 Debugging the API

Step 5 Publish the API.

API GatewayBest Practices 1 Querying Mobile Number Home Locations

Issue 01 (2020-06-02) Copyright © Huawei Technologies Co., Ltd. 6

Page 10: Best Practices - support.huaweicloud.com · API Gateway Best Practices Issue 01 Date 2020-06-02 HUAWEI TECHNOLOGIES CO., LTD

Figure 1-7 API list page

Figure 1-8 Publishing the API

----End

Calling the API

Step 1 In the API list, click the name of the created API, and then copy the API URL onthe displayed API details page.

API GatewayBest Practices 1 Querying Mobile Number Home Locations

Issue 01 (2020-06-02) Copyright © Huawei Technologies Co., Ltd. 7

Page 11: Best Practices - support.huaweicloud.com · API Gateway Best Practices Issue 01 Date 2020-06-02 HUAWEI TECHNOLOGIES CO., LTD

Figure 1-9 API details page

Figure 1-10 Copying the URL

Step 2 Paste the URL of the API in the address bar of a browser, and replace{phoneNumber} with the mobile number to be looked up.

The mobile number's origin information will be returned if the API is calledsuccessfully.

----End

API GatewayBest Practices 1 Querying Mobile Number Home Locations

Issue 01 (2020-06-02) Copyright © Huawei Technologies Co., Ltd. 8

Page 12: Best Practices - support.huaweicloud.com · API Gateway Best Practices Issue 01 Date 2020-06-02 HUAWEI TECHNOLOGIES CO., LTD

Binding a Request Throttling Policy

Step 1 Create a request throttling policy.

Step 2 Bind the request throttling policy to the API.

Step 3 Call the API by copying its URL to a browser. For more information, see Callingthe API.

If the API is called more than 20 times within one minute, an error will bereported.

----End

API GatewayBest Practices 1 Querying Mobile Number Home Locations

Issue 01 (2020-06-02) Copyright © Huawei Technologies Co., Ltd. 9

Page 13: Best Practices - support.huaweicloud.com · API Gateway Best Practices Issue 01 Date 2020-06-02 HUAWEI TECHNOLOGIES CO., LTD

Viewing Metrics

Step 1 On the APIs page, click the API to display the details page.

Step 2 On the Monitoring tab page, view the API metrics, including requests, latency,data traffic, and errors.

Step 3 Click View Metric to view complete metrics on the Cloud Eye console.

Monitoring data is retained for two days. For longer retention periods, save the monitoringdata to an Object Storage Service (OBS) bucket.

----End

API GatewayBest Practices 1 Querying Mobile Number Home Locations

Issue 01 (2020-06-02) Copyright © Huawei Technologies Co., Ltd. 10

Page 14: Best Practices - support.huaweicloud.com · API Gateway Best Practices Issue 01 Date 2020-06-02 HUAWEI TECHNOLOGIES CO., LTD

2 Opening Huawei Cloud Service Instances

Overview

The best practice for HUAWEI CLOUD API Gateway guides you through APIopening and calling.

With API Gateway, you can open your instances on other Huawei cloud servicessuch as Cloud Container Engine (CCE) and Cloud Service Engine (CSE).

Using API Gateway to open instances has the following benefits:

● No need to set elastic IP addresses, reducing your costs.● Allowed to choose a suitable authentication mode from multiple options,

enhancing access security.● Configure request throttling policies to ensure more secure access to backend

services.● Load balancing implemented between instances, optimizing resource

utilization and increasing system reliability.

This chapter provides guidance on using API Gateway to access CCE instances.

Figure 2-1 Using API Gateway to access CCE instances

Preparing CCE Workloads

Before opening instances through API Gateway, create clusters and workloads inCCE, and add instances and containers to the workloads. For more information,see the Cloud Container Engine User Guide.

API GatewayBest Practices 2 Opening Huawei Cloud Service Instances

Issue 01 (2020-06-02) Copyright © Huawei Technologies Co., Ltd. 11

Page 15: Best Practices - support.huaweicloud.com · API Gateway Best Practices Issue 01 Date 2020-06-02 HUAWEI TECHNOLOGIES CO., LTD

Collect required information according to the following figures, in which workloadcce-test is used as an example.

Figure 2-2 Viewing the VPC access port

Figure 2-3 Viewing the name of the ECS to which the instances belong

API GatewayBest Practices 2 Opening Huawei Cloud Service Instances

Issue 01 (2020-06-02) Copyright © Huawei Technologies Co., Ltd. 12

Page 16: Best Practices - support.huaweicloud.com · API Gateway Best Practices Issue 01 Date 2020-06-02 HUAWEI TECHNOLOGIES CO., LTD

Creating a VPC Channel

Step 1 Log in to the HUAWEI CLOUD management console, select a region in the upperleft corner, and choose Service List > Application > API Gateway.

Step 2 Choose API Publishing > VPC Channels, click Create VPC Channel, and set thebasic information (see Figure 2-5). Retain the default values for other parameters.

For details about the parameters, see the API Gateway User Guide.

API GatewayBest Practices 2 Opening Huawei Cloud Service Instances

Issue 01 (2020-06-02) Copyright © Huawei Technologies Co., Ltd. 13

Page 17: Best Practices - support.huaweicloud.com · API Gateway Best Practices Issue 01 Date 2020-06-02 HUAWEI TECHNOLOGIES CO., LTD

Figure 2-4 VPC channel list

Figure 2-5 Setting the basic information

Step 3 On the Add ECS page, click Add ECS to specify the ECS to which the to-be-openedinstances belong.

API Gateway supports load balancing between multiple instances.

API GatewayBest Practices 2 Opening Huawei Cloud Service Instances

Issue 01 (2020-06-02) Copyright © Huawei Technologies Co., Ltd. 14

Page 18: Best Practices - support.huaweicloud.com · API Gateway Best Practices Issue 01 Date 2020-06-02 HUAWEI TECHNOLOGIES CO., LTD

Step 4 Click Finish.

----End

Opening an API

Step 1 Create an API group. Figure 2-6 highlights this area.

Figure 2-6 Creating an API group

API GatewayBest Practices 2 Opening Huawei Cloud Service Instances

Issue 01 (2020-06-02) Copyright © Huawei Technologies Co., Ltd. 15

Page 19: Best Practices - support.huaweicloud.com · API Gateway Best Practices Issue 01 Date 2020-06-02 HUAWEI TECHNOLOGIES CO., LTD

Figure 2-7 Prompt message

Step 2 Create an API.

1. Set the basic information of the API.For details about the parameters, see the API Gateway User Guide.

Figure 2-8 API list

API GatewayBest Practices 2 Opening Huawei Cloud Service Instances

Issue 01 (2020-06-02) Copyright © Huawei Technologies Co., Ltd. 16

Page 20: Best Practices - support.huaweicloud.com · API Gateway Best Practices Issue 01 Date 2020-06-02 HUAWEI TECHNOLOGIES CO., LTD

Figure 2-9 Setting the basic information

2. On the Define API Request page, set the API request information.For details about the parameters, see the API Gateway User Guide.

3. On the Define Backend Request page, set the backend request information.For details about the parameters, see the API Gateway User Guide.

API GatewayBest Practices 2 Opening Huawei Cloud Service Instances

Issue 01 (2020-06-02) Copyright © Huawei Technologies Co., Ltd. 17

Page 21: Best Practices - support.huaweicloud.com · API Gateway Best Practices Issue 01 Date 2020-06-02 HUAWEI TECHNOLOGIES CO., LTD

4. On the Define Response page, set the success response shown in thefollowing figure.

5. Click Finish.

Step 3 Debug the API.

API GatewayBest Practices 2 Opening Huawei Cloud Service Instances

Issue 01 (2020-06-02) Copyright © Huawei Technologies Co., Ltd. 18

Page 22: Best Practices - support.huaweicloud.com · API Gateway Best Practices Issue 01 Date 2020-06-02 HUAWEI TECHNOLOGIES CO., LTD

Figure 2-10 API list

Figure 2-11 Debugging the API

Step 4 Publish the API.

Figure 2-12 API list

API GatewayBest Practices 2 Opening Huawei Cloud Service Instances

Issue 01 (2020-06-02) Copyright © Huawei Technologies Co., Ltd. 19

Page 23: Best Practices - support.huaweicloud.com · API Gateway Best Practices Issue 01 Date 2020-06-02 HUAWEI TECHNOLOGIES CO., LTD

Figure 2-13 Publishing the API

----End

Calling the API

Step 1 In the API list, click the created API, and then copy the URL on the displayed APIdetails page.

Figure 2-14 API list

Figure 2-15 Copying the URL

API GatewayBest Practices 2 Opening Huawei Cloud Service Instances

Issue 01 (2020-06-02) Copyright © Huawei Technologies Co., Ltd. 20

Page 24: Best Practices - support.huaweicloud.com · API Gateway Best Practices Issue 01 Date 2020-06-02 HUAWEI TECHNOLOGIES CO., LTD

Step 2 Paste the URL to the address bar of a browser. The following page is displayed ifthe API request is successful.

To limit the number of API calls received within a period, create a requestthrottling policy and bind it to the API. For more information, see the APIGateway User Guide.

----End

API GatewayBest Practices 2 Opening Huawei Cloud Service Instances

Issue 01 (2020-06-02) Copyright © Huawei Technologies Co., Ltd. 21