Best Practices - HUAWEI CLOUDOpening Huawei Cloud Service Instances Overview The best practice for...

23
API Gateway Best Practices Issue 01 Date 2018-08-20 HUAWEI TECHNOLOGIES CO., LTD.

Transcript of Best Practices - HUAWEI CLOUDOpening Huawei Cloud Service Instances Overview The best practice for...

API Gateway

Best Practices

Issue 01

Date 2018-08-20

HUAWEI TECHNOLOGIES CO., LTD.

Copyright © Huawei Technologies Co., Ltd. 2019. All rights reserved.No part of this document may be reproduced or transmitted in any form or by any means without prior writtenconsent 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 and thecustomer. All or part of the products, services and features described in this document may not be within thepurchase 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, guarantees orrepresentations 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 (2018-08-20) Copyright © Huawei Technologies Co., Ltd. i

Contents

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

2 Opening Huawei Cloud Service Instances.............................................................................10

API GatewayBest Practices Contents

Issue 01 (2018-08-20) Copyright © Huawei Technologies Co., Ltd. ii

1 Querying Mobile Number Home Locations

Overview

The best practice for HUAWEI CLOUD API Gateway guides you through API opening andcalling.

This chapter provides guidance on opening an API for a mobile number location lookupservice and publishing the API in the RELEASE environment. It also presents instructions onbinding 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 API hosting servicethat helps enterprises to build, manage, and deploy APIs at any scale.

What You Can Do with API Gateway

l Easily create, manage, and deploy APIs at any scale.

l Configure flexible request throttling policies to ensure continuous, stable API services.

l Monitor API services in terms of multiple metrics.

Preparing the Environment

Before using API Gateway to open the mobile number location lookup service, obtain ausername and password for logging in to the HUAWEI CLOUD console. The username musthave completed real-name authentication. In addition, collect required information accordingto Table 1-1.

Table 1-1 Environment information

Item Example

API group name PhoneNumberGroup

API name PhoneNumber

Authentication mode None

API GatewayBest Practices 1 Querying Mobile Number Home Locations

Issue 01 (2018-08-20) Copyright © Huawei Technologies Co., Ltd. 1

Item Example

Request path /test/{phoneNumber}

Backend address apigdemo.myhuaweicloud.com

Backend request path /api/mobile/{phoneNumber}

Environment RELEASE

Request throttling policyname

PhoneNumberThrottling

Throttling period 1 minute

API maximum 20

User maximum 10

Opening an API

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

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

Figure 1-1 Creating an API group

API GatewayBest Practices 1 Querying Mobile Number Home Locations

Issue 01 (2018-08-20) Copyright © Huawei Technologies Co., Ltd. 2

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 about the parameters, see the API Gateway User Guide.

Figure 1-3 API list

API GatewayBest Practices 1 Querying Mobile Number Home Locations

Issue 01 (2018-08-20) Copyright © Huawei Technologies Co., Ltd. 3

Figure 1-4 Setting basic API 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 1 Querying Mobile Number Home Locations

Issue 01 (2018-08-20) Copyright © Huawei Technologies Co., Ltd. 4

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

5. Click Finish.

Step 4 Debug the API.

Figure 1-5 API list

API GatewayBest Practices 1 Querying Mobile Number Home Locations

Issue 01 (2018-08-20) Copyright © Huawei Technologies Co., Ltd. 5

Figure 1-6 Debugging the API

Step 5 Publish the API.

Figure 1-7 API list

Figure 1-8 Publishing the API

----End

API GatewayBest Practices 1 Querying Mobile Number Home Locations

Issue 01 (2018-08-20) Copyright © Huawei Technologies Co., Ltd. 6

Calling the API

Step 1 In the API list, click the created API, and then copy the API URL.

Figure 1-9 API list

Figure 1-10 Copying the URL

Step 2 Paste the URL of the API on the address bar of a browser, and replace {phoneNumber} withthe mobile number to be queried.

Information on the mobile number's origin will be returned if the API is called successfully.

----End

API GatewayBest Practices 1 Querying Mobile Number Home Locations

Issue 01 (2018-08-20) Copyright © Huawei Technologies Co., Ltd. 7

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 details, see Calling the API.

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

----End

API GatewayBest Practices 1 Querying Mobile Number Home Locations

Issue 01 (2018-08-20) Copyright © Huawei Technologies Co., Ltd. 8

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 More Metrics to view complete metrics on the Cloud Eye console.

NOTE

Metrics data is retained for two days. For longer retention periods, save data to an OBS bucket.

----End

API GatewayBest Practices 1 Querying Mobile Number Home Locations

Issue 01 (2018-08-20) Copyright © Huawei Technologies Co., Ltd. 9

2 Opening Huawei Cloud Service Instances

OverviewThe best practice for HUAWEI CLOUD API Gateway guides you through API opening andcalling.

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

Using API Gateway to open instances has the following benefits:

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

access security.l Configure request throttling policies to ensure more secure access to backend services.l 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 WorkloadsBefore opening instances through API Gateway, create clusters and workloads in CCE, andadd instances and containers to the workloads. For more information, see the CloudContainer Engine User Guide.

Collect required information according to the following figures, in which workload cce-test isused as an example.

API GatewayBest Practices 2 Opening Huawei Cloud Service Instances

Issue 01 (2018-08-20) Copyright © Huawei Technologies Co., Ltd. 10

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 (2018-08-20) Copyright © Huawei Technologies Co., Ltd. 11

Creating a VPC Channel

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

Step 2 Choose API Publishing > VPC Channels, click Create VPC Channel, and set the basicinformation (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 (2018-08-20) Copyright © Huawei Technologies Co., Ltd. 12

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 (2018-08-20) Copyright © Huawei Technologies Co., Ltd. 13

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 (2018-08-20) Copyright © Huawei Technologies Co., Ltd. 14

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 (2018-08-20) Copyright © Huawei Technologies Co., Ltd. 15

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 (2018-08-20) Copyright © Huawei Technologies Co., Ltd. 16

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

5. Click Finish.

Step 3 Debug the API.

API GatewayBest Practices 2 Opening Huawei Cloud Service Instances

Issue 01 (2018-08-20) Copyright © Huawei Technologies Co., Ltd. 17

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 (2018-08-20) Copyright © Huawei Technologies Co., Ltd. 18

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 API detailspage.

Figure 2-14 API list

Figure 2-15 Copying the URL

API GatewayBest Practices 2 Opening Huawei Cloud Service Instances

Issue 01 (2018-08-20) Copyright © Huawei Technologies Co., Ltd. 19

Step 2 Paste the URL to the address bar of a browser. The following page is displayed if the APIrequest is successful.

To limit the number of API calls received within a period, create a request throttling policyand bind it to the API. For more information, see the API Gateway User Guide.

----End

API GatewayBest Practices 2 Opening Huawei Cloud Service Instances

Issue 01 (2018-08-20) Copyright © Huawei Technologies Co., Ltd. 20