Routing method, device, equipment and system of API gateway

By using custom routing policy condition expressions, the API gateway enables different requests for the same target API to be routed to different backend nodes, solving the problem of single policy matching in existing technologies and improving the application flexibility and applicability of the API gateway.

CN116132349BActive Publication Date: 2026-01-16TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202111348547.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-11-15
Publication Date
2026-01-16
Estimated Expiration
2041-11-15

AI Technical Summary

Technical Problem

The existing API gateway has a single policy matching, which limits the application scenarios of API request routing and cannot meet the diverse needs of users in different application scenarios.

Method used

By using custom routing policy conditional expressions, the API gateway can route different requests for the same target API to different backend nodes, enabling flexible routing policy matching.

Benefits of technology

It expands the flexibility of API gateway usage, supports various application scenarios such as canary deployment, blue-green deployment, and tenant routing, and improves the flexibility and applicability of API request routing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116132349B_ABST
    Figure CN116132349B_ABST
Patent Text Reader

Abstract

The application discloses a routing method of an API gateway. The API gateway receives an API request sent by a client, matches the API request with a condition expression of a custom routing strategy in the case that at least one custom routing strategy corresponding to a target API exists, and routes the API request to a custom backend node corresponding to the custom routing strategy in the case that the API request matches the condition expression of the custom routing strategy successfully. The condition expression of the custom routing strategy defined by a user enables the API gateway to route different API requests for the same target API to different backend nodes.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] Embodiments of the present application relate to the field of cloud computing, and in particular, to a routing method, device, equipment and system of an API gateway. BACKGROUND

[0002] Cloud technology refers to a hosting technology that unifies a series of resources such as hardware, software and network to realize data calculation, storage, processing and sharing in a wide area network or a local area network. A platform for implementing cloud technology is referred to as a cloud platform.

[0003] With the gradual increase of different demands of users on data in different application scenarios, a user can call different backends on a cloud platform through a client. For example, when testing the performance of two products, after an application programming interface (API) request is sent by a client to an API gateway, the API gateway needs to route a part of API requests of the client to a backend corresponding to a policy A and route another part of API requests of the client to a backend corresponding to a policy B.

[0004] In related technologies, the policy matching of an API gateway is single, which greatly limits the application scenarios of routing API requests through the API gateway. SUMMARY

[0005] The present application provides a routing method, device, equipment and system of an API gateway, which routes different API requests for a same target API to different backend nodes through a custom routing policy condition expression. The technical solution is as follows:

[0006] According to an aspect of the present application, a routing method of an API gateway is provided, which comprises:

[0007] receiving an API request sent by a client, the API request being used to request a service of a target API;

[0008] in a case where at least one custom routing policy corresponding to the target API exists, matching the API request with a condition expression of the custom routing policy;

[0009] in a case where the API request matches the condition expression of the custom routing policy successfully, routing the API request to a custom backend node corresponding to the custom routing policy.

[0010] According to an aspect of the present application, a routing device of an API gateway is provided, which comprises:

[0011] receiving a request for an API sent by a client, the request being used to request a service of a target API;

[0012] matching the request for the API with a condition expression of a custom routing strategy corresponding to the target API, if there is at least one custom routing strategy corresponding to the target API;

[0013] routing the request for the API to a custom backend node corresponding to the custom routing strategy, if the request for the API matches the condition expression of the custom routing strategy successfully.

[0014] According to another aspect of the present application, there is provided a routing system of an API gateway, the system comprising:

[0015] an API gateway and a cloud platform, the cloud platform comprising at least one API gateway, the API gateway comprising the routing device of the API gateway as described in the above aspect.

[0016] According to another aspect of the present application, there is provided a computer device, comprising a processor and a memory, the memory storing at least one computer instruction, the at least one computer instruction being loaded and executed by the processor to implement the routing method of the API gateway as described in the above aspect.

[0017] According to another aspect of the present application, there is provided a computer storage medium, the computer readable storage medium storing at least one computer instruction, the at least one computer instruction being loaded and executed by the processor to implement the routing method of the API gateway as described in the above aspect.

[0018] According to another aspect of the present application, there is provided a computer program product, the computer program product comprising computer instructions stored in a computer readable storage medium; the computer instructions being read and executed by a processor of a computer device from the computer readable storage medium, so that the computer device implements the routing method of the API gateway as described in the above aspect.

[0019] The technical solutions provided by the present application have at least the following beneficial effects:

[0020] The API gateway receives an API request sent by a client, and the API gateway matches the API request with a condition expression of a custom routing strategy. In a case where the API request matches the condition expression of the custom routing strategy successfully, the API request is routed to a custom backend node corresponding to the custom routing strategy. The condition expression of the custom routing strategy enables the API gateway to route different API requests for a same target API to different backend nodes, and thus can be applied to various application scenarios such as gray release, blue-green release, and tenant routing. For example, in the blue-green release, API requests meeting the condition expression are routed to a trial node of a new version, and API requests not meeting the condition expression are routed to a trial node of an old version. BRIEF DESCRIPTION OF DRAWINGS

[0021] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed in the embodiment description will be briefly introduced. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative effort.

[0022] Figure 1 is a schematic diagram of an application scenario of a routing system involved in a routing method of an API gateway provided by an example embodiment of the present application;

[0023] Figure 2 is a flowchart of a routing method of an API gateway provided by an example embodiment of the present application;

[0024] Figure 3 is a flowchart of a routing method of an API gateway provided by an example embodiment of the present application;

[0025] Figure 4 is a flowchart of syntax checking of a condition expression provided by an example embodiment of the present application;

[0026] Figure 5 is a schematic diagram of an abstract syntax tree of a condition expression provided by an example embodiment of the present application;

[0027] Figure 6 is a schematic diagram of a request result tree provided by an example embodiment of the present application;

[0028] Figure 7 is a flowchart of generation of an inverted index table provided by an example embodiment of the present application;

[0029] Figure 8 is a schematic diagram of a multi-level inverted index matching mode provided by an example embodiment of the present application;

[0030] Figure 9 is a flowchart of a routing method of an API gateway provided by an example embodiment of the present application;

[0031] Figure 10 is a flowchart of a routing method of an API gateway provided by an example embodiment of the present application;

[0032] Figure 11 is a flowchart of a routing method of an API gateway provided by an example embodiment of the present application;

[0033] Figure 12 is a system framework schematic diagram of a routing method of an API gateway provided by an example embodiment of the present application;

[0034] Figure 13 is a system framework schematic diagram of a routing method of an API gateway provided by an example embodiment of the present application;

[0035] Figure 14 is a block diagram of a routing device of an API gateway provided by an example embodiment of the present application;

[0036] Figure 15 is a structural schematic diagram of a computer device provided by an example embodiment of the present application. DETAILED DESCRIPTION

[0037] In order to make the purpose, technical scheme and advantages of the present application clearer, the embodiments of the present application will be further described in detail below with reference to the drawings.

[0038] In order to facilitate the reader to understand, the terms related to the embodiments of the present application are explained below.

[0039] Cloud platform: also known as cloud system, cloud environment or cloud, is a software system of cloud technology (also known as cloud computing technology) service provided by a cloud vendor.

[0040] Public cloud: is a cloud platform provided by a third-party public cloud vendor for a large number of individuals or enterprises. In the public cloud, hardware, software and other structures are owned and managed by the third-party public cloud vendor.

[0041] Private cloud: is a dedicated cloud platform provided for an enterprise or organization. The private cloud can be operated internally by the corresponding enterprise or organization. The private cloud is mainly for enterprise users, also known as enterprise cloud.

[0042] Hybrid cloud: refers to a cloud platform formed by different cloud platforms. The hybrid cloud includes at least two cloud platforms, also known as a multi-cloud platform or a multi-cloud. Optionally, the hybrid cloud integrates a public cloud and a private cloud. For security considerations, some enterprise users prefer to store data in a private cloud, but at the same time, they also want to obtain the computing resources of a public cloud. In this case, a hybrid cloud including a public cloud and a private cloud is increasingly adopted. The hybrid cloud mixes and matches the public cloud and the private cloud to obtain good use effect.

[0043] Virtual machine (VM): refers to a complete computer system running in an isolated environment by software simulation, which has complete hardware system functions. The work that can be completed in an entity computer (referred to as entity machine) can be realized in the virtual machine. When creating a virtual machine in a computer, part of the hard disk and memory capacity of the entity computer needs to be used as the hard disk and memory capacity of the virtual machine. Optionally, each virtual machine has an independent complementary metal oxide semiconductor (CMOS), hard disk and operating system, and the virtual machine can be operated like an entity computer.

[0044] Container: also referred to as container image, is a lightweight independent executable software package of software established by using container technology. Container technology refers to a virtualization technology in a computer operating system, which enables a process to run in a relatively independent and isolated environment (including an independent file system, namespace and / or resource view, etc.), thereby simplifying the deployment process of software, enhancing the portability and security of software, and improving the utilization rate of system resources. Container technology is widely used in service scenarios in the field of cloud computing.

[0045] Application program interface: also referred to as program interface, is an "interface between programs and operating systems" provided by an operating system of a cloud platform to users, such as programmers. The interface is used by users when programming. The user can access resources in the cloud platform and obtain corresponding services through the application program interface. An application program interface is a set of definitions, functions, programs and / or protocols. For example, an application program interface of a cloud platform includes one or more system calls, and each system call is a program that can complete a specific function.

[0046] API gateway (Application Programming Interface Gate Way, APIGW): a gateway providing API hosting services, which can uniformly authenticate, meter, publish and / or control the flow of APIs, etc.

[0047] Service: including computing service, storage service or network service, etc. The device or function accessible to the client on the cloud platform can be regarded as the service provided by the cloud platform.

[0048] Resource: hardware or software resource for providing service. For example, corresponding to computing service, storage service or network service, resource includes computing resource, storage resource or network resource. Optionally, computing resource includes central processing unit (CPU) resource, memory resource and / or hard disk resource, etc.

[0049] Plug-in: refers to the core program of API gateway processing request, and the corresponding API request can be accurately intercepted and loaded by setting plug-in.

[0050] Figure 1 is an application scenario diagram of the routing system of the API gateway involved in the API gateway routing method provided by the embodiment of the application. As shown in Figure 1 The API gateway routing system includes one or more clients 101 and multiple cloud platforms 102. Each cloud platform 102 includes an API gateway 1021, and each cloud platform 102 is deployed with two or more backend nodes for providing service for the client 101, and the multiple cloud platforms 102 correspond to the multiple API gateways 1021 one by one. Optionally, the API gateway 101 establishes a communication connection with the client 101. The client 101 can realize communication with the backend through the API gateway 1021. Optionally, the client 101 is a computer device such as computer or notebook computer. Optionally, the client 101 can be installed with a client, and the user realizes communication with the API gateway 1021 through the client. The client is usually programmed by the user.

[0051] Among them, Figure 1 Only two cloud platforms 102 and one client 101 are taken as examples for description, and the number of cloud platforms and the number of clients in the communication system are not limited.

[0052] Figure 2 is a flowchart of the API gateway routing method provided by an example embodiment of the application. The method can be executed by the API gateway in the system as Figure 1 shown. The method includes:

[0053] Step 202: receiving the API request sent by the client.

[0054] Exemplarily, the API gateway receives the API request sent by the client, and the API request is used to request the service of the target API.

[0055] Step 204: In the case that there is at least one custom routing policy corresponding to the target API, matching the API request with the condition expression of the custom routing policy.

[0056] By way of example, the routing policy refers to a judgment policy of whether the API request can be routed by the API gateway to the corresponding backend node. The custom routing policy refers to a routing policy set according to user needs. A custom routing policy includes a condition expression, which is a trigger condition of the custom routing policy, used to judge whether the API request meets the condition, i.e., in the case that the API request meets the condition expression, the API request meets the corresponding custom routing policy.

[0057] Optionally, the target API is bound with a conditional routing plug-in, and the user can create at least one custom routing policy in the conditional routing plug-in according to needs. When the API gateway receives the API request, the API gateway determines the target API corresponding to the API request, and the API gateway matches the API request with the condition expression in the custom routing policy corresponding to the target API.

[0058] Optionally, when creating the custom routing policy, the user needs to determine the policy name, policy weight, condition expression (trigger condition), backend type and backend configuration of the custom routing policy.

[0059] Optionally, when creating the custom routing policy, the policy name of the custom routing policy is no more than 50 characters, and the policy names of the custom routing policies created in the same routing plug-in must not be the same. The policy weight of the custom routing policy is used to represent the priority of the custom routing policy, and the greater the weight of the custom routing policy, the higher the priority of the custom routing policy. For example, the policy weight of the custom routing policy can be represented by a positive integer between 0 and 100. In the case that the policy weight is not determined, the default policy weight of the custom routing policy is 0. In the case that the policy weights of the custom routing policies are the same, the priority of the custom routing policy is determined by the creation time of the custom routing policy. For example, after the API gateway receives the API request, the API gateway will match the API request with the custom routing policy with the highest priority.

[0060] Optionally, when creating the custom routing policy, the condition expression in the custom routing policy is used to judge whether the API request meets the condition. In the case that the API request meets the condition expression, the API request matches the custom routing policy successfully.

[0061] Optionally, when creating the custom routing policy, it is necessary to determine the type of backend supported by the API gateway, the type of backend including at least one of a wide area network, a uniform resource locator (URL), an internet protocol (IP), a virtual private cloud (VPC), a serverless cloud function (SCF), a mock object, and a Tencent service framework (TSF). At the same time, the configuration of the backend is determined, and the user inputs the configuration information of the backend through yet another markup language (YAML).

[0062] Step 206: In the case where the API request matches the condition expression of the custom routing policy successfully, the API request is routed to the custom backend node corresponding to the custom routing policy.

[0063] The API gateway receives the API request sent by the client, and in the case where the API request matches the condition expression of the custom routing policy corresponding to the target API successfully, that is, the API request satisfies the condition expression in the custom routing policy, the API gateway routes the API request to the backend node corresponding to the condition expression in the custom routing policy.

[0064] Optionally, the custom backend node can be the same as or different from the default backend node corresponding to the target API.

[0065] Step 208: In the case where the API request does not match the condition expression of the custom routing policy successfully, the API gateway routes the API request to the default backend node corresponding to the target API.

[0066] The API gateway receives the API request sent by the client, and in the case where the API request does not match the condition expression of the custom routing policy corresponding to the target API successfully, that is, the API request does not satisfy the condition expression in the custom routing policy, the API gateway routes the API request to the default backend node corresponding to the target API.

[0067] To sum up, the method provided in the embodiment receives an API request sent by a client, and routes the API request to a custom backend node corresponding to a target API in a case where the API request matches a condition expression of a custom routing strategy successfully. The condition expression of the custom routing strategy defined by a user enables the API gateway to route different API requests for a same target API to different backend nodes, greatly expanding the flexibility of the API gateway.

[0068] Figure 3 FIG. 1 is a flowchart of a routing method of an API gateway provided in an example embodiment of the present application. The method can be performed by the API gateway in the system as shown in FIG. 1. The method includes the following steps. Figure 1

[0069] Step 302: receiving an API request sent by a client.

[0070] For example, the API gateway receives an API request sent by a client, and the API request is used to request a service of a target API.

[0071] Step 304: matching the API request with a condition expression of a custom routing strategy in a case where there is at least one custom routing strategy corresponding to the target API.

[0072] The API gateway receives an API request sent by a client, and the API gateway matches a path and a method in the API request with a condition expression of a custom routing strategy. The condition expression is used to indicate a routing trigger condition defined by a user.

[0073] Optionally, the condition expression needs to support a request parameter in a specific position, which is a parameter defined in the form of a parameter position and a parameter name in the condition expression, and corresponds to a request parameter in the API request defined in advance. The request parameter in the specific position supports at least one of a request header (Header) parameter, a query (Query) parameter, and a path (Path) parameter. For example, the position and the parameter name of the Header parameter are configured as a, and the Header.a is used to indicate the parameter in the condition expression. The Path parameter has no parameter name, and thus is indicated by path. For example, the condition expression is path = ' / test', which means that the condition expression is met when the request path in the request parameter in the API request is ' / test'. The parameter value of the Path parameter needs to start with ' / '.

[0074] ​Optionally, the conditional expression supports system parameters. The system parameters refer to system parameters in the API gateway. For example, the conditional expression can use the sysparam form to refer to the system parameters of the current request, and the system parameters do not need to be defined in the conditional expression to be referred to, but if a parameter with the same name is defined in the conditional expression, the system parameter taken will be overwritten by the self-defined parameter. The system parameters that can be used in the conditional expression include: sysparam.clientIp: client IP; sysparam.httpScheme: request protocol HTTP, HTTPS; sysparam.clientUa: at least one of the client uploaded UserAgent field, which is not limited by the embodiments of the application.

[0075] Optionally, the conditional expression supports the conditions of multiple expressions and, or, supports priority semantics (parentheses), supports simple arithmetic operations, and supports syntax checking. The conditional expression supports multiple expressions concatenated with "and" and "or" operators, for example, Header.Accept="text / plain" and Query.username="tom" or Path=" / test"; the conditional expression supports priority semantics (parentheses), that is, the expressions in the parentheses are executed first, for example, Header.Accept="text / plain" and Query.username="tom" or Path=" / test" and (Query.need_verify=false or sysparam.clientIp="123.123.123.1" and exists(Query.password)); the conditional expression supports simple arithmetic operations and supports syntax checking, that is, the conditional expression supports simple arithmetic operations in the expression, and each expression can implement syntax checking.

[0076] It should be noted that the API gateway matches the request parameters in the API request with the conditional expression of the custom routing strategy in the following manner:

[0077] Step S1: The request parameters in the API request are matched with the conditional expression of the custom routing strategy in a code snippet matching manner.

[0078] The code snippet matching manner is a manner of matching the request parameters and the conditional expression into the same code snippet. The code snippet refers to a runnable function including the request parameters and the conditional expression.

[0079] In a possible implementation, the condition expression in the custom routing strategy is syntax translated to obtain a translated condition expression; the request parameter of the API request is substituted into the translated condition expression to generate a code snippet; the output result of the code snippet is calculated in a sandbox, and the output result is used to indicate the matching result of the request parameter of the API request and the condition expression of the custom routing strategy.

[0080] In a possible implementation, the condition expression in the custom routing strategy is syntax translated to obtain a translated condition expression; the request parameter of the API request is substituted into the translated condition expression to generate a code snippet; the output result of the code snippet is calculated in a sandbox, and the output result is used to indicate the matching result of the request parameter of the API request and the condition expression of the custom routing strategy.

[0081] In a possible implementation, the API gateway pre-processes the request parameter in the received API request, retains the parameters in the request parameter of the API request that meet the API configuration by comparing the request parameter in the API request with the API configuration in the API gateway, and obtains pre-processed request parameters; the API gateway syntax translates the condition expression in the custom routing strategy to obtain a lua syntax translated condition expression, for example, the function in the condition expression is Random(), regex( <param> , <regex>), exists( <param> ), math.random(), string.match( <param> , <regex>), <param> ; the preprocessed request parameters are substituted into the condition expression translated by the Lua syntax to build a runnable function, and a generated Lua code snippet, for example, the generated code snippet can be represented as: local query, header, path, sysparam = …; return <translated_condition>; after obtaining the Lua code snippet, the obtained Lua code snippet is loaded in the sandbox, and the Lua code snippet is calculated to obtain the matching result of the request parameters of the API request and the condition expression of the custom routing strategy.

[0082] For example, the condition expression of the custom routing strategy A in the API gateway is:

[0083] Header.Accept = "text / plain" and Query.username = "tom" or Path = ' / test' and (Query.need_verify = false or sysparam.clientIp = '123.123.123.1' and exists(Query.password)).

[0084] The condition expression translated by the Lua syntax is:

[0085] "Header.Accept == "text / plain" and Query.username == "tom" or Path == " / test" and (Query.need_verify == false or sysparam.clientIp == "123.123.123.1" and Query.password)".

[0086] The Lua code snippet generated by combining the condition expression translated by the Lua syntax and the preprocessed request parameters is:

[0087] Local query, header, path, sysparam = …; return Header.Accept == "text / plain" and Query.username == "tom" or Path == " / test" and (Query.need_verify == false or sysparam.clientIp == "123.123.123.1" and Query.password) end.

[0088] The request parameters in the API request one received by the API gateway are shown in Table 1:

[0089] Table 1 API request one

[0090] Parameter Name Parameter Position Parameter Value Accept Header text / plain username Query tom need_verify Query false Path / testme clientIp System Parameter 123.123.123.1

[0091] The result obtained by running the lua code snippet is True, that is, the matching result of the request parameters of the API request and the condition expression of the custom routing strategy is Yes, and the API gateway receives the API request and routes it to the backend node corresponding to the custom routing strategy A.

[0092] Step S2: The request parameters in the API request are matched with the condition expression of the custom routing strategy in a policy tree matching manner.

[0093] The policy tree matching manner is a manner of matching the request parameters with the policy tree constructed based on the condition expression. The policy tree refers to expressing the condition expression in a tree form by using the logical operators between each expression in the condition expression.

[0094] In a possible implementation, a policy tree corresponding to the custom routing strategy is obtained; the request parameters of the API request are substituted into the policy tree to generate a request result tree; the request result tree is used to indicate the matching result of the request parameters of the API request and the condition expression of the custom routing strategy. The request result tree refers to the policy tree constructed based on the condition expression, the request parameters of the API request are substituted into the policy tree, and the matching result of the request parameters of the API request and the condition expression of the custom routing strategy is obtained according to the matching relationship between the request parameters of the API request and each expression in the policy tree, that is, the request result tree is obtained.

[0095] It can be understood that the policy tree corresponding to the condition expression can be generated before the API gateway receives the API request, or the policy tree corresponding to the condition expression is generated at the same time when the API gateway receives the API request, and the embodiments of the application do not limit this.

[0096] In a possible implementation, the condition expression in the custom routing strategy includes multiple types of encrypted strings Token, and the condition expression in the custom routing strategy is considered legal only when all Tokens in the condition expression meet the syntax specification and the expression syntax is parsed correctly. Otherwise, the expression syntax check fails. When creating the condition expression in the custom routing strategy, the API gateway performs syntax checking on the condition expression, and the syntax checking categories in the condition expression include at least one of an operand, an operator, and a function, which are not limited by the embodiments of the application. Table 2 shows the Tokens supported by the condition expression and the corresponding checking rules. It can be understood that the Tokens supported by the condition expression and the corresponding checking rules are not limited to this.

[0097] Table 2: Tokens supported by the condition expression and the corresponding checking rules

[0098]

[0099] Figure 4 A flowchart of the condition expression syntax checking is shown. The syntax checking of the condition expression is performed by the API gateway.

[0100] Step 401: Start.

[0101] Step 402: Traverse the custom routing strategy.

[0102] When the condition expression is limited to syntax checking, all condition expressions in the custom routing strategy are traversed, and step 403 is performed on the searched condition expression.

[0103] Step 403: Condition expression conversion.

[0104] The searched condition expression is preprocessed, that is, the regular expression is used to convert "=" to "==", so as to realize unification.

[0105] Step 404: Token checking.

[0106] After preprocessing the condition expression, all Tokens in the condition expression are parsed using the scheduling field algorithm, and whether the operators in the operator stack and the operands in the output sequence meet the rules is judged in turn.

[0107] Step 405: Whether all Tokens meet the specification.

[0108] It is judged whether all Tokens in the condition expression meet the specification, and if the Tokens do not meet the rules or the operators do not match in the syntax checking process, step 406 is performed, otherwise, step 407 is performed.

[0109] Step 406: Condition expression check fails.

[0110] In the syntax checking process of the condition expression, when the Token does not conform to the rule or the operator does not match, output condition expression check fails.

[0111] Step 407: Whether the condition expression is legal.

[0112] In the syntax checking process of the condition expression, when all Tokens in the condition expression conform to the rule or the operator matches, determine whether the condition expression is legal. If the condition expression is legal, output a string of postfix notation, i.e., a postfix expression. If the condition expression is not legal, execute step 408.

[0113] Step 408: Condition expression check fails.

[0114] In the case where the condition expression is not legal, output condition expression check fails.

[0115] Step 409: End.

[0116] In a possible implementation, after the syntax checking of the condition expression of the custom routing strategy, an Abstract Syntax Tree (AST) is constructed for the condition expression after the syntax checking.

[0117] In a possible implementation, at least two condition parameters in the condition expression of the custom routing strategy and an and, or relationship between the at least two condition parameters are obtained; leaf nodes are constructed by using the at least two condition parameters, and upper layer nodes of the leaf nodes are constructed by using the logical operation relationship of the at least two condition parameters, to obtain a strategy tree.

[0118] For example, the condition expression in the custom routing strategy B in the API gateway is Header.Accept="text / plain" and Query.username="tom" or Path=" / test", and the AST tree constructed thereby is as shown in Figure 5 .

[0119] Figure 5 The condition parameters in the condition expression in the custom routing policy B can be represented as condition parameter 1: Header. Accept = "text / plain", condition parameter 2: Query. username = "tom", and condition parameter 3: Path = ' / test'. The format of the condition parameter is: position. name = parameter value. The condition parameter 1, the condition parameter 2, and the condition parameter 3 are leaf nodes of the AST tree, and the logical operation relationship between the condition parameter 1, the condition parameter 2, and the condition parameter 3 is a node above the leaf nodes. The condition expression in the custom routing policy B can be represented as: condition parameter 1 and condition parameter 2 or condition parameter 3. That is, both the condition parameter 1 and the condition parameter 2 need to be met to meet the condition expression in the custom routing policy B, or only the condition parameter 3 needs to be met to meet the condition expression in the custom routing policy B, or both the condition parameter 1, the condition parameter 2, and the condition parameter 3 need to be met to meet the condition expression in the custom routing policy B.

[0120] For example, in the blue-green release application scenario, the condition expression in the custom routing policy B can be set as: age = 24 and address = China or model = 13.0 version. Therefore, each condition parameter in the condition expression can be represented as condition parameter 1: age = 24, condition parameter 2: address = China, and condition parameter 3: model = 13.0 version. In the case that the request parameters of the API request meet both the age of 24 and the address in China, the request parameters of the API request match the custom routing policy B; or in the case that the request parameters of the API request meet the model of 13.0 version, the request parameters of the API request match the custom routing policy B.

[0121] Alternatively, the condition expression in the custom routing policy includes at least one of age, address, model, and purchase date, but is not limited thereto.

[0122] The API request two received by the API gateway is shown in Table 3:

[0123] Table 3 API request two

[0124] Parameter Name Parameter Position Parameter Value Accept Header application / json username Query tom Path / testme

[0125] Based on the AST tree constructed based on the condition expression in the custom routing policy B in the API gateway, the request result tree is generated according to the API request two received by the API gateway, as shown in Figure 6 According to the results of each node, the final policy matching result is no, and the API gateway cannot route the API request two to the backend node corresponding to the custom routing policy B. The API gateway can route the API request two to the default backend node.

[0126] Figure 6 The request result tree obtained by substituting the request parameters of the API request into the AST tree constructed by the conditional expression in the custom routing strategy B is shown. As shown in Figure 6 The request parameters of the API request are substituted into the AST tree constructed by the conditional expression in the same type parameter position, for example, the request parameters of the API request are: Header. Accept = "application / json", and the request parameters are substituted into the AST tree in the same type position, that is, the request parameters are substituted into the position of the conditional parameter 1 in the AST tree: Header. Accept = "text / plain". After matching, the parameter value "application / json" of the request parameters of the API request is different from the parameter value "text / plain" of the conditional parameter in the AST tree, so "no" is displayed at the node, indicating that the parameter value "application / json" of the request parameters of the API request does not match the parameter value "text / plain" of the conditional parameter in the AST tree. Substitute all request parameters in the API request into the AST tree, and obtain the matching result of each parameter at each node, and finally obtain the matching result of the request parameters of the API request and the conditional expression in the custom routing strategy B by using the logical operation relationship between the nodes.

[0127] For example: the parameter values corresponding to the request parameters in the API request two are: parameter 1: application / json; parameter 2: tom; parameter 3: / testme. Substitute parameter 1, parameter 2 and parameter 3 in the request parameters into the positions of conditional parameter 1, conditional parameter 2 and conditional parameter 3 in the AST tree for comparison and matching, and then generate the matching result between the parameters in the request parameters and the corresponding conditional parameters at the corresponding nodes. As shown in Figure 6 Parameter 1 in the request parameters does not match conditional parameter 1 in the AST tree, so the matching result "no" is generated at the node; parameter 2 in the request parameters matches conditional parameter 2 in the AST tree, so the matching result "yes" is generated at the node; parameter 3 in the request parameters does not match conditional parameter 3 in the AST tree, so the matching result "no" is generated at the node; according to the logical operation relationship between the nodes, the final matching result of the request parameters of the API request and the conditional expression in the custom routing strategy B is "no", that is, the request parameters of the API request do not match the conditional expression in the custom routing strategy B.

[0128] Optionally, in Figure 6 The logical operation relationship between the condition parameter 1 and the condition parameter 2 in the middle AST tree is "and", so as long as at least one of the matching results of the condition parameter 1 and the parameter 1 in the request parameter or the matching results of the condition parameter 2 and the parameter 2 in the request parameter is "no", the upper node formed by the condition parameter 1 and the condition parameter 2 is "no". It can be understood that the logical operation relationship between the condition parameter 1 and the condition parameter 2 is "and", that is, only when the matching result of the condition parameter 1 and the parameter 1 in the request parameter is "yes" and the matching result of the condition parameter 2 and the parameter 2 in the request parameter is "yes", the upper node formed by the condition parameter 1 and the condition parameter 2 is "yes". It can be understood that the logical operation relationship between the condition parameter 1 and the condition parameter 2 is "and", and in the case that the matching result of the condition parameter 1 and the parameter 1 in the request parameter is "no", there is no need to verify the matching result of the condition parameter 2 and the parameter 2 in the request parameter.

[0129] Step S3: The request parameters in the API request are matched with the condition expression of the custom routing strategy in a reverse index matching manner.

[0130] In a possible implementation, an inverted index table is obtained, and the custom routing strategy matching the request parameters of the API request is queried in the inverted index table.

[0131] Figure 7 A generation flowchart of the inverted index table is shown. The generation of the inverted index table is implemented by the API gateway.

[0132] Step 702: A Boolean expression is generated.

[0133] The condition expression in the custom routing strategy is converted into a Boolean expression, that is, the and connector in the condition expression is converted into ∩ operation, and the or connector is converted into ∪ operation. The Boolean expression means that the expressions in the condition expression are connected in an and / or manner.

[0134] For example, the condition expression in the custom routing strategy in the API gateway is:

[0135] Routing strategy 1: Header. Accept = "text / plain" and Query. username = "clare" or Path = ' / test' or sysparam. stage ='release'.

[0136] Routing strategy 2: Query. brand = "only" or Query. brand = "Unique" or Query. level > 3.

[0137] Route policy 3: (sysparam.stage='test' or sysparam.stage='release') and sysparam.httpScheme='HTTPS'.

[0138] The corresponding Boolean expression of the condition expression of the custom routing policy in the API gateway after conversion is:

[0139] Route policy 1 (Boolean expression): Header.Accept="text / plain"∩Query.username="clare"U Path=" / test"U sysparam.stage='release'.

[0140] Route policy 2 (Boolean expression): Query.brand="only"U Query.brand="Unique"U Query.level>3.

[0141] Route policy 3 (Boolean expression): (sysparam.stage='test'U sysparam.stage='release')∩sysparam.httpScheme='HTTPS'.

[0142] Step 704: Generate disjunctive normal form.

[0143] Based on the Boolean expression corresponding to the condition expression of the custom routing policy after conversion, the API gateway converts the Boolean expression into disjunctive normal form. The disjunctive normal form refers to expanding all possible expression combination modes of the Boolean expression, for example, (a+b)*c, which can be expressed as: a*c+b*c after conversion.

[0144] For example, based on the converted Boolean expression, the API gateway converts the Boolean expression into disjunctive normal form, and the corresponding disjunctive normal form is:

[0145] Route policy 1 (disjunctive normal form): Header.Accept="text / plain"∩Query.username="clare"U sysparam.stage='release'U Path=" / test".

[0146] Route policy 2 (disjunctive normal form): Query.brand="only"U Query.brand="Unique"U Query.level>3.

[0147] Route policy 3 (disjunctive normal form): (sysparam.stage = 'test'∩sysparam.httpScheme = 'HTTPS') U (sysparam.stage ='release'∩sysparam.httpScheme = 'HTTPS').

[0148] Step 706: Constructing the inverted index table.

[0149] Based on the disjunctive normal form, the inverted index table is constructed, and the obtained inverted index table is shown in Table 4.

[0150] Table 4 Inverted index table

[0151] Serial Number Disjunctive Normal Form Routing Strategy J1 Header.Accept="text / plain"∩Query.username="clare" Routing Strategy 1 J2 Path=' / test' Routing Strategy 1 J3 Query.brand="only" Routing Strategy 2 J4 Query.brand="Unique" Routing Strategy 2 J5 Query.level>3 Routing Strategy 2 J6 sysparam.stage='test'∩sysparam.httpScheme='HTTPS' Routing Strategy 3 J7 sysparam.stage='release'∩sysparam.httpScheme='HTTPS' Routing Strategy 3 J8 sysparam.stage='release' Routing Strategy 1

[0152] Based on the API gateway, the inverted index table is constructed. When the API gateway receives the API request three, the API gateway pre-processes the request parameters in the API request three, retains the parameters in the request parameters of the API request three that meet the API configuration by comparing the request parameters in the API request three with the API configuration in the API gateway, obtains the pre-processed request parameters, and compares the pre-processed API request three in the inverted index table to find the disjunctive normal form that meets the API request three.

[0153] For example, the API request three received by the API gateway is: Header. Accept = "application / json" and Header. attribute = "collllllor" and Query. username = "clare222" and Query. age = 10.

[0154] Comparing the API request three and the inverted index table constructed by the API gateway, Table 5 can be obtained.

[0155] Table 5 API request three and inverted index table corresponding table

[0156] Request Parameter Disjunctive Normal Form Custom Routing Strategy Header.Accept="application / json" None None Header.attribute="collllllor" None None Query.username="clare222" None None Query.age=10 None None

[0157] As can be seen from Table 5, the API request three received by the API gateway has no matching custom routing policy.

[0158] For example, the API request four received by the API gateway is: Query. brand = "only" and sysparam. stage ='release' and Path = ' / test'.

[0159] Comparing the API request four and the inverted index table constructed by the API gateway, Table 6 can be obtained.

[0160] Table 6 API request four and inverted index table corresponding table

[0161] Request Parameter Disjunctive Normal Form Custom Routing Strategy Query.brand="only" J3 Custom Routing Strategy 2 sysparam.stage='release' J8 Custom Routing Strategy 1 Path=' / test' J2 Custom Routing Strategy 1

[0162] As shown in Table 6, the API request four received by the API gateway can match the custom routing policy 1 and the custom routing policy 2.

[0163] Optionally, in the case that the API request four received by the API gateway can match the custom routing policy 1 and the custom routing policy 2, the API request four received by the API gateway can be routed to the backend node corresponding to the custom routing policy 1 through the API gateway in a random manner, or be routed to the backend node corresponding to the custom routing policy 2 through the API gateway in a random manner, or be selected according to the weight of the custom routing policy 1 and the custom routing policy 2, for example, the weight of the custom routing policy 1 is greater than the weight of the custom routing policy 2, so the API request four received by the API gateway is routed to the backend node corresponding to the custom routing policy 1 through the API gateway, or be selected according to the custom time of the custom routing policy 1 and the custom routing policy 2, for example, the custom time of the custom routing policy 1 is earlier than the custom time of the custom routing policy 2, so the API request four received by the API gateway can be routed to the backend node corresponding to the custom routing policy 2 through the API gateway, or be routed to the backend node corresponding to the custom routing policy 1 through the API gateway.

[0164] It can be understood that the inverted index table corresponding to the condition expression in the custom routing policy can be generated before the API gateway receives the API request, or the strategy tree corresponding to the condition expression is generated at the same time when the API gateway receives the API request, and the embodiments of the present application are not limited thereto. Moreover, the inverted index table corresponding to the condition expression in the custom routing policy can be repeatedly used after being generated for the first time, that is, in the case that the API gateway receives multiple API requests, the inverted index table generated for the first time can be used for query.

[0165] In a possible implementation, when there are many elements of the condition expression in the custom routing policy, if the inverted index matching mode is adopted, when the inverted index table is constructed, many disjunctive normal forms need to be constructed, and the hit rate of the API request and the inverted index table is not high, therefore, the multi-level inverted index matching mode can be used, as shown in Table 7, after the API gateway receives the API request, that is, the request parameter in the API request is matched with the atomic disjunctive normal form, that is, the request parameter in the API request is matched with a single element in the disjunctive normal form, and then the matching is performed level by level, and finally the matching result is obtained. Figure 8

[0166] For example, as shown in Table 8, the API request four received by the API gateway can be routed to the backend node corresponding to the custom routing policy 1 through the API gateway in a random manner, or be routed to the backend node corresponding to the custom routing policy 2 through the API gateway in a random manner, or be selected according to the weight of the custom routing policy 1 and the custom routing policy 2, for example, the weight of the custom routing policy 1 is greater than the weight of the custom routing policy 2, so the API request four received by the API gateway is routed to the backend node corresponding to the custom routing policy 1 through the API gateway, or be selected according to the custom time of the custom routing policy 1 and the custom routing policy 2, for example, the custom time of the custom routing policy 1 is earlier than the custom time of the custom routing policy 2, so the API request four received by the API gateway can be routed to the backend node corresponding to the custom routing policy 2 through the API gateway, or be routed to the backend node corresponding to the custom routing policy 1 through the API gateway.​ Figure 8 As shown, the API request received by the API gateway is: Query.brand = "only" and sysparam.stage ='release' and Path = ' / test'. The request parameters in the API request are matched with the single elements in the disjunctive normal form, that is, the request parameters in the API request are matched with the first-level elements in the disjunctive normal form, and the first-level elements in the disjunctive normal form are all single elements, and the parameters 1: Query.brand = "only", the parameters 2: sysparam.stage ='release', and the parameters 3: sysparam.stage = 'test' in the request parameters of the API request are sequentially matched with the first-level elements in the disjunctive normal form; after the atomic disjunctive normal forms matching the parameters 1, the parameters 2, and the parameters 3 in the request parameters of the API request are determined in the first-level elements, the second-level disjunctive normal form is matched, the second-level disjunctive normal form associated with the atomic disjunctive normal form matching the parameters 1, the parameters 2, and the parameters 3 in the request parameters of the API request is queried in the second-level disjunctive normal form, and finally the third-level disjunctive normal form is matched, and finally the matching result is obtained.

[0167] For example, the parameters 1, the parameters 2, and the parameters 3 in the request parameters of the API request are sequentially matched with the first-level elements in the disjunctive normal form; after the atomic disjunctive normal forms matching the parameters 1, the parameters 2, and the parameters 3 are determined in the first-level elements, the second-level disjunctive normal form is matched, the second-level disjunctive normal form matching the parameters 1, the parameters 2, and the parameters 3 is queried in the second-level disjunctive normal form, and finally the third-level disjunctive normal form is matched, and finally the matching result is obtained. Figure 8 It can be known that the API request received by the API gateway can match the custom routing strategy 1 and the custom routing strategy 2.

[0168] In a possible implementation, when there are more elements in the condition expression in the custom routing strategy, if the inverted index matching mode is adopted, when the inverted index table is constructed, more disjunctive normal forms need to be constructed, and the construction of more disjunctive normal forms occupies more memory space, therefore, a bitmap can be used to replace tree storage, after the condition expression of the custom routing strategy is converted into a disjunctive normal form, a bitmap Bitmap of the condition expression is constructed, as shown in Table 7, 1 is counted for a disjunctive normal form included in the condition expression, and 0 is counted for a disjunctive normal form not included in the condition expression.

[0169] Table 7 Bitmap of condition expression

[0170]

[0171] For example, routing strategy 1: Header. Accept = "text / plain" ∩ Query. username = "clare" U Path = ' / test' U sysparam. stage ='release'.

[0172] Routing strategy 2: Query. brand = "only" U Query. brand = "Unique" U Query. level > 3.

[0173] Routing strategy 3: (sysparam. stage = 'test' ∩ sysparam. httpScheme = 'HTTPS') U (sysparam. stage ='release' ∩ sysparam. httpScheme = 'HTTPS').

[0174] API request 1: Query. brand = "only" and Header. attribute = "colllllllor" and Query. username = "clare222" and Header. Accept = "application / json".

[0175] API request 2: Query. brand = "only" and sysparam. stage ='release' and Path = ' / test'.

[0176] For API request 2, according to Table 7, it can be known that the bitmap corresponding to Path = ' / test' is 100, the bitmap corresponding to sysparam.stage ='release' is 100, and the bitmap corresponding to Query.brand = "only" is 001. Then, the bitmaps corresponding to various request parameters are taken or, and the result of taking or of the above three bitmaps is 101, that is, the API request 2 received by the API gateway can match the custom routing policy 1 and the custom routing policy 2.

[0177] Step 306: In the case that the API request matches the condition expression of the custom routing policy successfully, the API request is routed to the custom backend node corresponding to the custom routing policy.

[0178] In the case that the API request matches the condition expression of the custom routing policy corresponding to the target API successfully by any one of the code snippet matching manner, the policy tree matching manner, and the inverted index matching manner, that is, the API request satisfies the condition expression in the custom routing policy by any one of the code snippet matching manner, the policy tree matching manner, and the inverted index matching manner, the API gateway routes the API request to the backend node corresponding to the condition expression in the custom routing policy.

[0179] Step 308: In the case that the API request does not match the condition expression of the custom routing policy successfully, the API gateway routes the API request to the default backend node corresponding to the target API.

[0180] In the case that the API request does not match the condition expression of the custom routing policy corresponding to the target API successfully, that is, the API request does not satisfy the condition expression in the custom routing policy, the API gateway routes the API request to the default backend node corresponding to the target API.

[0181] In summary, the method provided in this embodiment receives an API request sent by a client, and in the case that the API request matches a condition expression of a custom routing policy successfully by any one of a code snippet matching manner, a policy tree matching manner, and an inverted index matching manner, routes the API request to a custom backend node corresponding to a target API. The condition expression of the user-defined routing policy provided in this embodiment provides three matching manners of the API request and the condition expression, so that the API gateway can route the API request in various application scenarios, greatly expanding the use flexibility of the API gateway.

[0182] Figure 9 is a flowchart of a routing method of an API gateway provided by an example embodiment of the present application. The method can be performed by the API gateway in the system as shown in Figure 1 The method includes the following steps.

[0183] Step 902: receiving an API request sent by a client.

[0184] For example, the API gateway receives an API request sent by a client, and the API request is used to request a service of a target API.

[0185] Step 904: in a case where a number of custom routing strategies corresponding to the target API is not greater than a number threshold, matching a request parameter in the API request with a condition expression of the custom routing strategy in a code snippet matching manner or a strategy tree matching manner.

[0186] In a possible implementation, in a case where the number of custom routing strategies corresponding to the target API in the API gateway is equal to or lower than a first threshold, when the API gateway receives the API request, the API gateway matches the request parameter in the API request with the condition expression of the custom routing strategy in the code snippet matching manner or the strategy tree matching manner.

[0187] The detailed description of matching the request parameter in the API request with the condition expression of the custom routing strategy in the code snippet matching manner can be found in the above description of step S1, and will not be repeated here.

[0188] Optionally, the first threshold is determined by at least one of manual setting or dynamic setting by the API gateway, and the embodiments of the present application do not limit this.

[0189] The detailed description of matching the request parameter in the API request with the condition expression of the custom routing strategy in the strategy tree matching manner can be found in the above description of step S2, and will not be repeated here.

[0190] For example, the first threshold is set to 100, and in a case where the number of custom routing strategies in the API gateway is less than or equal to 100, when the API gateway receives the API request, the API gateway matches the request parameter in the API request with the condition expression of the custom routing strategy in the code snippet matching manner or the strategy tree matching manner.

[0191] In a possible implementation, when the number of custom routing strategies corresponding to the target API in the API gateway is equal to or lower than the first threshold, and the code snippet does not contain definitions that are not supported by the sandbox, the request parameters in the API request are matched with the condition expressions of the custom routing strategies in a code snippet matching manner; and when the code snippet contains definitions that are not supported by the sandbox, the request parameters in the API request are matched with the condition expressions of the custom routing strategies in a strategy tree matching manner.

[0192] Optionally, the definitions that are not supported by the sandbox include at least one of garbled code, a dead loop, and illegal code, which are not limited in the present application.

[0193] Figure 10 A flowchart is shown for the API gateway to match the request parameters in the API request with the condition expressions of the custom routing strategies in a code snippet matching manner or a strategy tree matching manner when the number of custom routing strategies corresponding to the target API in the API gateway is equal to or lower than the first threshold.

[0194] Step 1001: API request preprocessing.

[0195] After the API gateway receives the API request, the API request preprocessing is performed on the request parameters in the API request, the request parameters in the API request are compared with the API configuration in the API gateway, the parameters in the API request that meet the API configuration are retained, and the preprocessed request parameters are obtained.

[0196] Step 1002: Condition expression translation.

[0197] The API gateway performs lua syntax translation on the condition expressions in the custom routing strategies, and obtains the lua syntax translated condition expressions.

[0198] Step 1003: Generating a lua code snippet.

[0199] The preprocessed request parameters are substituted into the lua syntax translated condition expressions, and are constructed into a runnable function to generate a lua code snippet.

[0200] Step 1004: Loading the lua code snippet in the sandbox.

[0201] After the lua code snippet is obtained, the obtained lua code snippet is loaded in the sandbox.

[0202] Step 1005: Judging whether the loading is successful.

[0203] If the loaded Lua code snippet is determined to be successfully loaded, the process proceeds to step 1007; otherwise, the process proceeds to step 1006.

[0204] Step 1006: Constructing a request result tree.

[0205] If the code snippet contains definitions unsupported by the sandbox, a strategy tree corresponding to the custom routing strategy is obtained; the request parameters of the API request are substituted into the strategy tree to generate a request result tree. The step of matching the request parameters in the API request with the conditional expressions of the custom routing strategy using the strategy tree matching manner can be referred to step S2 described above, and will not be described here.

[0206] Step 1007: Running the Lua code snippet.

[0207] If the code snippet does not contain definitions unsupported by the sandbox, the obtained Lua code snippet is loaded in the sandbox, and the Lua code snippet is calculated to obtain the matching result of the request parameters of the API request and the conditional expressions of the custom routing strategy. The step of matching the request parameters in the API request with the conditional expressions of the custom routing strategy using the code snippet matching manner can be referred to step S1 described above, and will not be described here.

[0208] Step 1008: Obtaining the matching result.

[0209] After the API gateway matches the request parameters in the API request with the conditional expressions of the custom routing strategy using the code snippet matching manner or the strategy tree matching manner, the matching result of the request parameters in the API request and the conditional expressions of the custom routing strategy is obtained.

[0210] The API gateway routes the API request to the custom backend node corresponding to the target API according to the matching result of the request parameters in the API request and the conditional expressions of the custom routing strategy.

[0211] Step 906: In a case where the number of custom routing strategies corresponding to the target API is greater than a threshold, the request parameters in the API request are matched with the conditional expressions of the custom routing strategies using an inverted index matching manner.

[0212] In a possible implementation, in a case where the number of custom routing strategies corresponding to the target API in the API gateway is greater than a first threshold, when the API gateway receives the API request, the API gateway matches the request parameters in the API request with the conditional expressions of the custom routing strategies using the inverted index matching manner.

[0213] The request parameters in the API request and the condition expression of the custom routing strategy are matched in a reverse index matching manner. Details are described above in step S3, and will not be repeated here.

[0214] In summary, the method provided in the embodiment receives an API request sent by a client. When the number of custom routing strategies corresponding to a target API in the API gateway is equal to or lower than a first threshold, the API gateway matches the request parameters in the API request with the condition expression of the custom routing strategy in a code snippet matching manner or a strategy tree matching manner. When the number of custom routing strategies corresponding to the target API in the API gateway is greater than the first threshold, the API gateway matches the request parameters in the API request with the condition expression of the custom routing strategy in a reverse index matching manner. The condition expression of the custom routing strategy provided by the user provides three matching manners of the API request and the condition expression corresponding to different numbers of custom routing strategies in the API gateway, so that the API gateway can route the API request in various application scenarios, greatly expanding the use flexibility of the API gateway.

[0215] Figure 11 is a flowchart of a routing method of an API gateway provided by an example embodiment of the present application. The method can be performed by the API gateway in the system as shown in Figure 1 The method includes the following steps.

[0216] Step 1102: Routing matching is performed on the API request to determine the target API of the API request.

[0217] For example, the API gateway receives an API request sent by a client, and performs routing matching on the API request to determine the target API corresponding to the API request.

[0218] Figure 12 A system framework schematic diagram of the routing method of the API gateway is shown. After the API gateway receives an API request sent by a client, the API request is determined to correspond to a target API through routing matching.

[0219] Step 1104: Plugin matching is performed on the target API to determine the condition routing plugin corresponding to the target API.

[0220] For example, as shown in Figure 12 After the API request is determined to correspond to a target API through routing matching, the API gateway performs plugin matching on the target API to determine the condition routing plugin corresponding to the target API through the plugin matching.

[0221] Optionally, one conditional routing plug-in can bind at least one target API, for example, one target API binds one conditional routing plug-in, or two APIs bind one conditional routing plug-in, but not limited thereto.

[0222] Step 1106: In the case that there is a conditional routing plug-in corresponding to the target API and the conditional routing plug-in is in an activated state, the custom routing strategy in the conditional routing plug-in is determined as the custom routing strategy corresponding to the target API.

[0223] After determining the conditional routing plug-in corresponding to the target API, it is determined whether the corresponding conditional routing plug-in is in an activated state. In the case that the corresponding conditional routing plug-in is in an activated state, the custom routing strategy in the conditional routing plug-in is determined as the custom routing strategy corresponding to the target API. The API gateway matches the request parameter in the API request with the condition expression of the custom routing strategy corresponding to the target API.

[0224] In summary, the method provided in the embodiment routes and matches the API request, determines the target API of the API request, performs plug-in matching on the target API, determines the conditional routing plug-in corresponding to the target API, and in the case that there is a conditional routing plug-in corresponding to the target API and the conditional routing plug-in is in an activated state, the custom routing strategy in the conditional routing plug-in is determined as the custom routing strategy corresponding to the target API. Through user-defined conditional routing plug-in, the API request is routed to the backend node corresponding to the matched custom routing strategy according to the custom routing strategy matched in the custom conditional routing plug-in, which greatly expands the use flexibility of the API gateway.

[0225] Figure 12 A system framework schematic diagram of a routing method of an API gateway is shown. The API gateway includes a data plane 1202 and a control plane 1204.

[0226] Exemplarily, the API request is received by the data plane 1202 of the API gateway, the API request is determined to correspond to a target API API1 through route matching, the API gateway performs plug-in matching on the target API API1, through the plug-in matching, it is determined that the conditional routing plug-in corresponding to the API1 is the conditional routing plug-in A; after it is determined that the conditional routing plug-in corresponding to the API1 is the conditional routing plug-in A, in the data plane 1202 of the API gateway, the conditional routing plug-in A preprocesses the request parameter in the API request, and the conditional expression in the conditional routing plug-in A is translated into lua syntax, the preprocessing step of the request parameter and the step of translating the conditional expression into lua syntax can be referred to step S1, the API request is matched with the conditional expression in the conditional routing plug-in A by using the strategy matching in the conditional routing plug-in A, the specific strategy matching step can be referred to step 304, in the case that the API request and the conditional expression in the conditional routing plug-in A are matched successfully, the API request is routed to the custom backend node corresponding to the API1 through the routing forwarding, that is, the API request is routed to the backend A.

[0227] In the management and control plane 1204 of the API gateway, the API gateway can construct the conditional routing plug-in corresponding to the target API and the custom routing strategy in the conditional routing plug-in in response to the custom operation of the user, and bind the target API with the conditional routing plug-in, and perform syntax checking on the conditional expression in the custom routing strategy in the constructed conditional routing plug-in. In addition, the API gateway can delete, activate or deactivate the conditional routing plug-in corresponding to the target API and the custom routing strategy in the conditional routing plug-in in response to other operations of the user.

[0228] In a possible implementation, when the user needs to construct the conditional routing plug-in, the conditional routing plug-in corresponding to the target API and the custom routing strategy in the conditional routing plug-in are generated in response to the custom operation of the user.

[0229] In a possible implementation, when the user does not need to use the conditional routing plug-in, the conditional routing plug-in corresponding to the target API and the custom routing strategy in the conditional routing plug-in are deleted in response to the deletion operation of the user.

[0230] In a possible implementation, when the user needs to activate the constructed conditional routing plug-in, the conditional routing plug-in corresponding to the target API and the custom routing strategy in the conditional routing plug-in are set to an activated state in response to the activation operation of the user.

[0231] In a possible implementation, the user sets the conditional routing plug-in corresponding to the target API and the custom routing strategy in the conditional routing plug-in to an inactive state in response to a deactivation operation of the user when the user does not need to use the conditional routing plug-in.

[0232] The conditional routing plug-in configuration customized by the user in the API gateway is decoupled from the target API configuration and can be stored and managed separately. The storage structure of the conditional routing plug-in configuration is shown in Table 8. The conditional routing plug-in and the target API are associated through an association table. For example, the conditional routing plug-in and the target API can be associated through attach_env_list. When the user needs to use the custom conditional routing plug-in, the conditional routing plug-in needs to be bound to the target API. In the binding process, the management and control plane 1204 of the API gateway needs to send the conditional routing plug-in configuration and the target API configuration to the data plane 1202 of the API gateway to achieve the binding. When the user does not need to use the custom conditional routing plug-in, the conditional routing plug-in needs to be unbound from the target API. In the unbinding process, the management and control plane 1204 of the API gateway also needs to send the conditional routing plug-in configuration and the target API configuration to the data plane 1202 of the API gateway to achieve the unbinding. When the conditional routing plug-in is modified or updated, the management and control plane 1204 of the API gateway only needs to send the conditional routing plug-in configuration to the data plane 1202 of the API gateway to achieve the modification or update.

[0233] Table 8 Storage structure of conditional routing plug-in configuration

[0234] Field Name Field Type Field Meaning attach_env_list Array(String) Target API bound by conditional routing plugin plugin_data Array(JSON) Conditional routing plugin definition data plugin_id String Conditional routing plugin ID plugin_type String Conditional routing plugin type

[0235] To sum up, the method provided in this embodiment performs routing matching on an API request, determines a target API of the API request, performs plug-in matching on the target API, determines a conditional routing plug-in corresponding to the target API, and determines a custom routing strategy in the conditional routing plug-in as a custom routing strategy corresponding to the target API. The user can customize the conditional routing plug-in and perform operations such as construction, deletion, activation, and deactivation on the conditional routing plug-in through custom operations, so that the API gateway can route API requests in various application scenarios, greatly expanding the use flexibility of the API gateway.

[0236] Figure 13 FIG. 1 is a schematic diagram of a system framework of a routing method of an API gateway provided in an example embodiment of the present application. The API gateway includes a data plane 1302 and a management and control plane 1304.

[0237] Exemplarily, the API request is received at the data plane 1302 of the API gateway, the API request is determined to correspond to a target API API1 through route matching, and the API request is routed to the backend 2 corresponding to the API1 without a conditional routing plug-in.

[0238] Exemplarily, a user creates a conditional routing plug-in, the API request is received at the data plane 1302 of the API gateway, the API request is determined to correspond to a target API API1 through route matching, the API gateway performs plug-in matching on the target API1, and it is determined through the plug-in matching that the conditional routing plug-in corresponding to the API1 is the conditional routing plug-in A. The user can create at least one routing policy in the conditional routing plug-in A. For example, the routing policies in the conditional routing plug-in A are arranged in descending order of weight as follows: routing policy 1, routing policy 2, routing policy 3, and routing policy 4. The request parameters of the API request are matched with the custom routing policies in the conditional routing plug-in A in turn according to the weight. After the request parameters of the API request are matched with the routing policy 2 in the conditional routing plug-in A, the API request is routed to the backend node corresponding to the routing policy 2, that is, the API request is routed to the backend 4.

[0239] It should be noted that, after the request parameters of the API request are matched with the custom routing policy, the API request is no longer matched with subsequent custom routing policies.

[0240] For example, in a blue-green publishing application scenario, two versions of an application are simultaneously run, that is, a new version and an old version are simultaneously run. A user can implement blue-green publishing by creating a conditional routing plug-in. The user creates the conditional routing plug-in, so that a part of API requests that do not satisfy a custom matching strategy in the conditional routing plug-in are routed to a default backend, and the default backend can be set as the old version. A part of API requests that satisfy the custom matching strategy in the conditional routing plug-in are routed to a backend corresponding to the custom matching strategy, that is, the new version, so as to implement blue-green publishing.

[0241] The routing method of the API gateway provided in the embodiments of the present application can be applied to at least one of a gray publishing (canary publishing) application scenario, a blue-green publishing application scenario, and a tenant routing application scenario, and the embodiments of the present application do not limit this.

[0242] For example, when product features A and B are tested, a user can set a condition expression in a custom routing policy. The API gateway can route a part of API requests of the user to a backend node corresponding to the product feature A and route another part of API requests of the user to a backend node corresponding to the product feature B, so as to implement gray publishing.

[0243] For example, when running both new and old versions of the backend simultaneously, users can set conditional expressions in their custom routing policies. The API gateway can then route some users' API requests to the backend nodes corresponding to the new version and others' API requests to the backend nodes corresponding to the old version, thereby achieving blue-green deployment.

[0244] For example, different tenants have different requirements for API resources and API security. The API gateway can route user API requests to different backend nodes based on different user characteristics by setting conditional expressions in the custom routing policy, thereby achieving tenant routing.

[0245] Figure 14 A schematic diagram of a routing apparatus for an API gateway provided in an exemplary embodiment of this application is shown. The apparatus includes:

[0246] The receiving module 1402 is used to receive an API request sent by a client, wherein the API request is used to request the service of a target API;

[0247] The matching module 1404 is used to match the API request with the conditional expression of the custom routing policy when there is at least one custom routing policy corresponding to the target API.

[0248] The routing module 1406 is used to route the API request to the custom backend node corresponding to the custom routing policy when the API request successfully matches the conditional expression of the custom routing policy.

[0249] In one possible implementation, the matching module 1404 is further configured to match the request parameters in the API request with the conditional expression of the custom routing strategy;

[0250] The conditional expression is used to indicate user-defined route triggering conditions.

[0251] In one possible implementation, the matching module 1404 is further configured to match the request parameters in the API request with the conditional expression of the custom routing strategy using a code-slice matching method; the code-slice matching method is a method of translating the request parameters and the conditional expression into the same code-slice for matching;

[0252] In a possible implementation, the matching module 1404 is further configured to match the request parameter in the API request with the condition expression of the custom routing strategy in a strategy tree matching manner; the strategy tree matching manner is a manner of matching the request parameter with a strategy tree constructed based on the condition expression.

[0253] In a possible implementation, the matching module 1404 is further configured to match the request parameter in the API request with the condition expression of the custom routing strategy in an inverted index matching manner; the inverted index matching manner is a manner of matching the request parameter with an inverted index constructed based on the condition expression.

[0254] In a possible implementation, the matching module 1404 is further configured to perform lua syntax translation on the condition expression in the custom routing strategy, to obtain a lua syntax translated condition expression.

[0255] The request parameter of the API request is substituted into the lua syntax translated condition expression, to generate a lua code snippet.

[0256] An output result of the lua code snippet is calculated in a sandbox, and the output result is used to indicate a matching result of the request parameter of the API request and the condition expression of the custom routing strategy.

[0257] In a possible implementation, the matching module 1404 is further configured to obtain a strategy tree corresponding to the custom routing strategy.

[0258] The request parameter of the API request is substituted into the strategy tree, to generate a request result tree; the request result tree is used to indicate a matching result of the request parameter of the API request and the condition expression of the custom routing strategy.

[0259] In a possible implementation, the matching module 1404 is further configured to obtain at least two condition parameters in the condition expression of the custom routing strategy, and a logical operation relationship between the at least two condition parameters.

[0260] Leaf nodes are constructed by using the at least two condition parameters, upper layer nodes of the leaf nodes are constructed by using the logical operation relationship of the at least two condition parameters, and the strategy tree is obtained.

[0261] In a possible implementation, the matching module 1404 is further configured to obtain an inverted index table, the inverted index table including a matching corresponding relationship of a request parameter and the custom routing strategy.

[0262] query the inverted index table for a custom routing policy matching the request parameter of the API request.

[0263] In a possible implementation, the matching module 1404 is further configured to convert a conditional expression in the custom routing policy into a Boolean expression;

[0264] convert the Boolean expression into a disjunctive normal form based on the Boolean expression;

[0265] construct the inverted index table based on the disjunctive normal form.

[0266] In a possible implementation, the routing module 1406 is further configured to, in a case where the API request fails to match the conditional expression of the custom routing policy, route the API request to a default backend node corresponding to the target API.

[0267] In a possible implementation, the matching module 1404 is further configured to, in a case where a quantity of custom routing policies corresponding to the target API is not greater than a quantity threshold, match the request parameter in the API request with the conditional expression of the custom routing policy by using the code snippet matching manner or the strategy tree matching manner;

[0268] In a case where the quantity of custom routing policies corresponding to the target API is greater than the quantity threshold, match the request parameter in the API request with the conditional expression of the custom routing policy by using the inverted index matching manner.

[0269] In a possible implementation, the matching module 1404 is further configured to, in a case where the code snippet does not contain a definition that is not supported by a sandbox, match the request parameter in the API request with the conditional expression of the custom routing policy by using the code snippet matching manner;

[0270] In a case where the code snippet contains a definition that is not supported by the sandbox, match the request parameter in the API request with the conditional expression of the custom routing policy by using the strategy tree matching manner.

[0271] In a possible implementation, the matching module 1404 is further configured to perform routing matching on the API request to determine the target API of the API request.

[0272] perform plug-in matching on the target API to determine a conditional routing plug-in corresponding to the target API;

[0273] In a case where the conditional routing plug-in corresponding to the target API exists and the conditional routing plug-in is in an activated state, a custom routing strategy in the conditional routing plug-in is determined as the custom routing strategy corresponding to the target API.

[0274] In a possible implementation, the matching module 1404 is further configured to, in response to a custom operation of the user, generate a conditional routing plug-in corresponding to the target API and a custom routing strategy in the conditional routing plug-in.

[0275] Or,

[0276] In response to a deletion operation of the user, the conditional routing plug-in corresponding to the target API and the custom routing strategy in the conditional routing plug-in are deleted.

[0277] Or,

[0278] In response to an activation operation of the user, the conditional routing plug-in corresponding to the target API and the custom routing strategy in the conditional routing plug-in are set to an activated state.

[0279] Or,

[0280] In response to a deactivation operation of the user, the conditional routing plug-in corresponding to the target API and the custom routing strategy in the conditional routing plug-in are set to a deactivated state.

[0281] Figure 15 A possible basic hardware architecture of the computer device provided by the embodiments of the present application is schematically provided.

[0282] Referring to Figure 15 The computer device 1500 includes a processor 1501, a memory 1502, a communication interface 1503, and a bus 1504.

[0283] In the computer device 1500, the number of the processor 1501 can be one or more, Figure 15 Only one of the processors 1501 is shown. Optionally, the processor 1501 can be a central processing unit (CPU). If the computer device 1500 has multiple processors 1501, the types of the multiple processors 1501 can be different or can be the same. Optionally, the multiple processors 1501 of the computer device 1500 can also be integrated as a multi-core processor.

[0284] The memory 1502 stores computer instructions and data; the memory 1502 can store computer instructions and data required to implement the communication method provided in the present application, for example, the memory 1502 stores instructions for implementing the steps of the routing method of the API gateway. The memory 1502 can be any one or any combination of the following storage media: non-volatile memory (for example, Read-Only Memory (ROM), Solid State Disk (SSD), Hard Disk Drive (HDD), optical disc), volatile memory.

[0285] The communication interface 1503 can be any one or any combination of the following devices: a network interface (for example, an Ethernet interface), a wireless network card, and the like devices with network access functions.

[0286] The communication interface 1503 is used for data communication between the computer device 1500 and other computer devices or terminals.

[0287] The bus 1504 can connect the processor 1501 with the memory 1502 and the communication interface 1503. In this way, the processor 1501 can access the memory 1502 and also use the communication interface 1503 to interact with other computer devices or terminals.

[0288] In the present application, the computer device 1500 executes computer instructions in the memory 1502, so that the computer device 1500 implements the routing method of the API gateway provided in the present application, or so that the computer device 1500 deploys the routing system of the API gateway.

[0289] In the exemplary embodiments, a non-transitory computer readable storage medium including instructions is also provided, for example, a memory including instructions, which can be executed by the processor of the server to complete the routing method of the API gateway shown in various embodiments of the present application. For example, the non-transitory computer readable storage medium can be a ROM, a Random Access Memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, and an optical data storage device, etc.

[0290] The embodiments of the present application also provide a routing system of an API gateway, which comprises: an API gateway and a cloud platform, the cloud platform comprising at least one API gateway, and the API gateway comprising the routing device of the API gateway provided in the above embodiments.

[0291] The embodiment of the application further provides a computer device, comprising a processor and a memory, and the memory stores at least one computer instruction, and the at least one computer instruction is loaded and executed by the processor to realize the routing method of the API gateway provided by each method embodiment.

[0292] The embodiment of the application further provides a computer storage medium, and the computer readable storage medium stores at least one computer instruction, and the at least one computer instruction is loaded and executed by a processor to realize the routing method of the API gateway provided by each method embodiment.

[0293] The embodiment of the application further provides a computer program product, and the computer program product comprises computer instructions, and the computer instructions are stored in a computer readable storage medium; the computer instructions are read and executed by a processor of a computer device from the computer readable storage medium, so that the computer device executes the routing method of the API gateway provided by each method embodiment.

[0294] It should be understood that "multiple" mentioned herein refers to two or more than two. "And / or", which describes the association relationship of associated objects, indicates that there can be three relationships, for example, A and / or B can represent: A exists alone, A and B exist simultaneously, and B exists alone. The character " / " generally represents that the associated objects before and after it are in an "or" relationship.

[0295] A person skilled in the art can understand that all or part of the steps of the above-mentioned embodiments can be completed by hardware, or by a program instructing relevant hardware, and the program can be stored in a computer readable storage medium. The storage medium mentioned above can be a read-only memory, a magnetic disk or an optical disk.

[0296] The above is only an optional embodiment of the application, and is not used to limit the application. Any modification, equivalent switching, improvement, etc. made within the spirit and principles of the application shall be included in the protection scope of the application.< / regex> < / regex>

Claims

1. A routing method of an API gateway, characterized by, The method comprises: receiving an API request sent by a client, the API request being used to request a service of a target API; in a case where a number of custom routing strategies corresponding to the target API is not greater than a number threshold, retaining parameters in the API request that meet API configurations in an API gateway by comparing the parameters in the API request with the API configurations, to obtain preprocessed request parameters; performing lua syntax translation on a conditional expression in the custom routing strategy to obtain a lua syntax translated conditional expression; substituting the preprocessed request parameters into the lua syntax translated conditional expression to generate a lua code snippet; loading the lua code snippet in a sandbox and determining whether loading the lua code snippet in the sandbox is successful; in a case where the code snippet does not contain definitions that are not supported by the sandbox, matching the request parameters in the API request with the conditional expression of the custom routing strategy by using a code snippet matching mode; in a case where the code snippet contains definitions that are not supported by the sandbox, obtaining a strategy tree corresponding to the custom routing strategy, the strategy tree being a tree-shaped representation of the conditional expression by using logical operators between each expression in the conditional expression; substituting the request parameters of the API request into a first branch in a corresponding leaf node in the strategy tree to generate a request result tree, each node in the request result tree displaying a matching result of each parameter; obtaining a matching result of the request parameters of the API request and the conditional expression by using a logical operation relationship between nodes in the request result tree; the strategy tree is constructed by using at least two conditional parameters in the conditional expression of the custom routing strategy to construct leaf nodes, and using a logical operation relationship of the at least two conditional parameters to construct upper nodes of the leaf nodes, so that each leaf node includes the first branch and a second branch, the first branch being at least one of a parameter position and a parameter name of a conditional parameter, and the second branch being a parameter value of the conditional parameter; in a case where the number of custom routing strategies corresponding to the target API is greater than the number threshold, matching the request parameters in the API request with the conditional expression of the custom routing strategy by using an inverted index matching mode; in a case where a number of elements of the conditional expression in the custom routing strategy corresponding to the target API is greater than a preset number, matching the request parameters in the API request with the conditional expression of the custom routing strategy by using a multi-level inverted index matching mode. In a case where the API request matches the condition expression of the custom routing strategy successfully, the API request is routed to a custom backend node corresponding to the custom routing strategy; and in a case where the API request fails to match the condition expression of the custom routing strategy, the API request is routed to a default backend node corresponding to the target API, so that different API requests requesting a same target API can be routed to different backend nodes. The condition routing plug-in configured by the user in the API gateway is decoupled from API configuration and is separately stored and managed, and the condition routing plug-in is associated with the target API through an association table. The custom routing strategy corresponds to a strategy weight, and the greater the weight of the custom routing strategy is, the higher the priority of the custom routing strategy is. In a case where the strategy weights of the custom routing strategies are the same, the priority of the custom routing strategy is determined according to the creation time of the custom routing strategy. The at least one custom routing strategy is matched with the API request in a priority order.

2. The method of claim 1, wherein, The condition expression is used to indicate a routing trigger condition defined by the user.

3. The method of claim 2, wherein, The code snippet matching manner is a manner of matching the request parameter and the condition expression in a same code snippet. The inverted index matching manner is a manner of matching the request parameter and an inverted index constructed based on the condition expression.

4. The method of claim 3, wherein, The matching of the request parameter in the API request and the condition expression of the custom routing strategy in the code snippet matching manner includes: Performing lua syntax translation on the condition expression in the custom routing strategy to obtain a lua syntax translated condition expression; Substituting the request parameter of the API request into the lua syntax translated condition expression to generate a lua code snippet; Calculating an output result of the lua code snippet in a sandbox, and the output result is used to indicate a matching result of the request parameter of the API request and the condition expression of the custom routing strategy.

5. The method of claim 3, wherein, The matching of the request parameter in the API request and the condition expression of the custom routing strategy in the inverted index matching manner includes: Obtaining an inverted index table, the inverted index table including a matching correspondence between a request parameter and the custom routing strategy; Querying, in the inverted index table, a custom routing strategy matching the request parameter of the API request.

6. The method of claim 5, wherein, The method further includes: Converting the condition expression in the custom routing strategy into a Boolean expression; Converting the Boolean expression into a disjunctive normal form based on the Boolean expression; Constructing the inverted index table based on the disjunctive normal form.

7. The method according to any one of claims 1 to 6, characterized in that, The method further includes: Performing routing matching on the API request to determine the target API of the API request; Performing plug-in matching on the target API to determine a condition routing plug-in corresponding to the target API; In a case where the conditional routing plug-in corresponding to the target API exists and the conditional routing plug-in is in an activated state, a custom routing strategy in the conditional routing plug-in is determined as a custom routing strategy corresponding to the target API.

8. The method of claim 1, wherein, The method further comprises: performing routing matching on the API request to determine the target API of the API request; performing plug-in matching on the target API to determine a conditional routing plug-in corresponding to the target API; In a case where the conditional routing plug-in corresponding to the target API exists and the conditional routing plug-in is in an activated state, a custom routing strategy in the conditional routing plug-in is determined as a custom routing strategy corresponding to the target API.

9. The method of any one of claims 1, 3-6, wherein, The method further comprises: in response to a custom operation of a user, generating a conditional routing plug-in corresponding to the target API and a custom routing strategy in the conditional routing plug-in; or, in response to a deletion operation of a user, deleting a conditional routing plug-in corresponding to the target API and a custom routing strategy in the conditional routing plug-in; or, in response to an activation operation of a user, setting a conditional routing plug-in corresponding to the target API and a custom routing strategy in the conditional routing plug-in to an activated state; or, in response to a deactivation operation of a user, setting a conditional routing plug-in corresponding to the target API and a custom routing strategy in the conditional routing plug-in to a deactivated state.

10. The method of claim 1, wherein, The method further comprises: in response to a custom operation of a user, generating a conditional routing plug-in corresponding to the target API and a custom routing strategy in the conditional routing plug-in; or, in response to a deletion operation of a user, deleting a conditional routing plug-in corresponding to the target API and a custom routing strategy in the conditional routing plug-in; or, in response to an activation operation of a user, setting a conditional routing plug-in corresponding to the target API and a custom routing strategy in the conditional routing plug-in to an activated state; or, in response to a deactivation operation of a user, setting a conditional routing plug-in corresponding to the target API and a custom routing strategy in the conditional routing plug-in to a deactivated state.

11. A routing apparatus of an API gateway, characterized by, The apparatus comprises: a receiving module configured to receive an API request sent by a client, the API request being used to request a service of a target API; The matching module is configured to: in a case where a number of custom routing strategies corresponding to the target API is not greater than a number threshold, reserve parameters in the request parameters of the API request that meet API configurations in the API gateway by comparing the request parameters in the API request with the API configurations, to obtain preprocessed request parameters; perform lua syntax translation on condition expressions in the custom routing strategies, to obtain lua syntax translated condition expressions; substitute the preprocessed request parameters into the lua syntax translated condition expressions, to generate a lua code snippet; load the lua code snippet in a sandbox, and determine whether loading the lua code snippet in the sandbox is successful; in a case where the code snippet does not contain definitions that are not supported by the sandbox, match the request parameters in the API request with the condition expressions of the custom routing strategies by using a code snippet matching manner; in a case where the code snippet contains definitions that are not supported by the sandbox, obtain a strategy tree corresponding to the custom routing strategy, the strategy tree being a tree-shaped form of the condition expressions by using logical operators between the condition expressions; substitute the request parameters of the API request into a first branch in a corresponding leaf node in the strategy tree, to generate a request result tree, each node of the request result tree displaying a matching result of each parameter; obtain a matching result of the request parameters of the API request and the condition expressions by using logical operation relationships between nodes in the request result tree; the strategy tree is constructed by using at least two condition parameters in the condition expressions of the custom routing strategy to construct leaf nodes, and by using logical operation relationships of the at least two condition parameters to construct upper nodes of the leaf nodes, so that each leaf node includes the first branch and a second branch, the first branch being at least one of a parameter position and a parameter name of a condition parameter, and the second branch being a parameter value of the condition parameter; in a case where the number of custom routing strategies corresponding to the target API is greater than the number threshold, match the request parameters in the API request with the condition expressions of the custom routing strategies by using an inverted index matching manner; in a case where a number of elements of the condition expressions in the custom routing strategies corresponding to the target API is greater than a preset number, match the request parameters in the API request with the condition expressions of the custom routing strategies by using a multi-level inverted index matching manner; The routing module is configured to: in a case where the API request matches the condition expressions of the custom routing strategies successfully, route the API request to a custom backend node corresponding to the custom routing strategy; and in a case where the API request fails to match the condition expressions of the custom routing strategies, route the API request to a default backend node corresponding to the target API, so that different API requests requesting the same target API can be routed to different backend nodes. The API gateway is configured with a user-defined conditional routing plug-in, and the conditional routing plug-in is associated with the target API through an association table.

12. The apparatus of claim 11, wherein, The conditional expression is used to indicate a user-defined routing trigger condition.

13. The apparatus of claim 12, wherein, The code piece matching manner is a manner of matching the request parameter and the conditional expression in a same code piece. The inverted index matching manner is a manner of matching the request parameter and an inverted index constructed based on the conditional expression.

14. The apparatus of claim 13, wherein, The matching module is further configured to: perform lua syntax translation on the conditional expression in the user-defined routing strategy, to obtain a lua syntax translated conditional expression; substitute the request parameter of the API request into the lua syntax translated conditional expression, to generate a lua code piece; calculate an output result of the lua code piece in a sandbox, and the output result is used to indicate a matching result of the request parameter of the API request and the conditional expression of the user-defined routing strategy.

15. The apparatus of claim 13, wherein, The matching module is further configured to: obtain an inverted index table, and the inverted index table includes a matching corresponding relationship between a request parameter and the user-defined routing strategy; query, in the inverted index table, a user-defined routing strategy that matches the request parameter of the API request.

16. The apparatus of claim 15, wherein, The matching module is further configured to: convert the conditional expression in the user-defined routing strategy into a Boolean expression; convert the Boolean expression into a disjunctive normal form based on the Boolean expression; construct the inverted index table based on the disjunctive normal form.

17. The apparatus of any one of claims 11 to 16, wherein, The matching module is further configured to: perform routing matching on the API request, to determine the target API of the API request; perform plug-in matching on the target API, to determine a conditional routing plug-in corresponding to the target API; in a case where the conditional routing plug-in corresponding to the target API exists and the conditional routing plug-in is in an activated state, determine a user-defined routing strategy in the conditional routing plug-in as a user-defined routing strategy corresponding to the target API.

18. The apparatus of claim 16, wherein, The matching module is further configured to: perform routing matching on the API request, to determine the target API of the API request; perform plug-in matching on the target API, to determine a conditional routing plug-in corresponding to the target API; in a case where the conditional routing plug-in corresponding to the target API exists and the conditional routing plug-in is in an activated state, determine a user-defined routing strategy in the conditional routing plug-in as a user-defined routing strategy corresponding to the target API.

19. The apparatus of any of claims 11, 13-16, wherein, The matching module is further configured to: In response to a user's custom operation, generating a conditional routing plug-in corresponding to the target API and a custom routing strategy in the conditional routing plug-in; or, In response to a user's deletion operation, deleting a conditional routing plug-in corresponding to the target API and a custom routing strategy in the conditional routing plug-in; or, In response to a user's activation operation, setting a conditional routing plug-in corresponding to the target API and a custom routing strategy in the conditional routing plug-in to an activated state; or, In response to a user's deactivation operation, setting a conditional routing plug-in corresponding to the target API and a custom routing strategy in the conditional routing plug-in to a deactivated state.

20. The apparatus of claim 11, wherein, The device further comprises: In response to a user's custom operation, generating a conditional routing plug-in corresponding to the target API and a custom routing strategy in the conditional routing plug-in; or, In response to a user's deletion operation, deleting a conditional routing plug-in corresponding to the target API and a custom routing strategy in the conditional routing plug-in; or, In response to a user's activation operation, setting a conditional routing plug-in corresponding to the target API and a custom routing strategy in the conditional routing plug-in to an activated state; or, In response to a user's deactivation operation, setting a conditional routing plug-in corresponding to the target API and a custom routing strategy in the conditional routing plug-in to a deactivated state.

21. A routing system of an API gateway, characterized in that, The system comprises: an API gateway and a cloud platform, the cloud platform comprising at least one API gateway, the API gateway comprising the routing device of the API gateway as claimed in any one of claims 11 to 20.

22. A computer device, comprising: The computer device comprises: a processor and a memory, the memory storing at least one computer instruction, the at least one computer instruction being loaded and executed by the processor to implement the routing method of the API gateway as claimed in any one of claims 1 to 10.

23. A computer storage medium, comprising, The computer readable storage medium stores at least one computer instruction, and the at least one computer instruction is loaded and executed by the processor to implement the routing method of the API gateway as claimed in any one of claims 1 to 10.

24. A computer program product, characterised in that, The computer program product comprises computer instructions stored in a computer readable storage medium; the computer instructions are read and executed by the processor of the computer device from the computer readable storage medium, so that the computer device executes the routing method of the API gateway as claimed in any one of claims 1 to 10.

Citation Information

Patent Citations

  • System and method for classifying API requests in API processing systems using a tree configuration

    US9667704B1