Application program interface (API) determination method and apparatus
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- BEIJING BAOLANDE SOFTWARE CORP
- Filing Date
- 2023-03-31
- Publication Date
- 2026-08-07
AI Technical Summary
[0005]本发明提供一种应用程序接口API确定,用以解决现有技术中API匹配效率低的问题
Smart Images

Figure CN116594665B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and in particular to a method and apparatus for determining application programming interfaces (APIs). Background Technology
[0002] In recent years, with the development of the Internet and the rapid application of microservices, the application of World Wide Web (WEB) containers has become very widespread, making gateways an indispensable component. The scenarios for managing and controlling Application Programming Interfaces (APIs) are also increasing. In certain specific scenarios, it is necessary to implement dynamic API management, controlling API uploading, decommissioning, or rate limiting. API proxies are one implementation method, controlling APIs through a proxy.
[0003] In related technologies, there are two implementation methods for proxy API matching: static matching and dynamic matching. Static matching involves pre-generating a path mapping table, typically a graph structure, where the key is the API request path and the value is the specific API. The API is precisely located based on the request path, and then the proxy API is controlled according to control rules. Static matching is efficient with almost no overhead, but its drawback is that it can only match one-to-one paths and cannot support fuzzy matching or regular expression matching. Dynamic matching uses pre-defined path matching rules to dynamically match paths, and then controls the API corresponding to the matched path according to control rules. Dynamic matching can handle complex requirements such as fuzzy matching and regular expression matching, but different matching rules result in significantly different implementation complexity and performance. When the number of paths to be matched is large, performance is low, making it difficult to meet the demands of high concurrency and high performance.
[0004] Therefore, path matching lacks a unified implementation solution, is limited to a single scenario, is difficult to reuse across different components, and has low API matching efficiency. Summary of the Invention
[0005] This invention provides an application programming interface (API) determination method to solve the problem of low API matching efficiency in the prior art.
[0006] This invention provides a method for determining an application programming interface (API), comprising:
[0007] At least one radix tree is constructed based on at least one proxy path and the proxy API identifier corresponding to each proxy path; the radix tree includes each proxy path and the proxy API identifier corresponding to each proxy path;
[0008] Upon receiving an API request, the target proxy API identifier is determined based on each of the cardinality trees and the request information included in the API request; wherein the request information is used to request access to the target API;
[0009] Based on the target proxy API identifier and the rule base, the target API is determined; the rule base includes at least one path matching rule, and each path matching rule corresponds to an API identifier.
[0010] According to a method for determining an application programming interface (API) provided by the present invention, the step of constructing at least one radix tree based on at least one proxy path and the proxy API identifier corresponding to each proxy path includes:
[0011] Obtain at least one pre-configured proxy path and the proxy API identifier corresponding to each of the proxy paths;
[0012] Each of the proxy paths is parsed to obtain the request information corresponding to each proxy path;
[0013] Each cardinality tree is constructed based on the request information and the proxy API identifier.
[0014] According to a method for determining an application programming interface (API) provided by the present invention, the request information includes request indication information and a request path. The step of determining the target proxy API identifier based on each cardinality tree and the request information included in the API request includes:
[0015] Based on the request indication information, a target cardinal tree is selected from each of the cardinal trees; the target cardinal tree corresponds to the request indication information.
[0016] Based on the target cardinality tree and the request path, the target proxy API identifier is determined.
[0017] According to a method for determining an application programming interface (API) provided by the present invention, determining the target proxy API identifier based on the target cardinality tree and the request path includes:
[0018] Based on the request path, find the target proxy path corresponding to the request path in the target cardinality tree;
[0019] The proxy API identifier corresponding to the target proxy path is determined as the target proxy API identifier.
[0020] According to a method for determining an application programming interface (API) provided by the present invention, the step of determining the target API based on the target proxy API identifier and a rule base includes:
[0021] The target proxy API identifier is matched with the proxy API identifier corresponding to each of the path matching rules included in the rule base;
[0022] If there is a match between the target proxy API identifier and each of the proxy API identifiers, the API corresponding to the proxy API identifier that matches the target proxy API identifier is determined as the target API.
[0023] According to a method for determining an application programming interface (API) provided by the present invention, the method further includes:
[0024] The path matching rule corresponding to the proxy API identifier that matches the target proxy API identifier is determined as the rule for the target API;
[0025] If the rule is online, the API request will be forwarded to the target API.
[0026] The present invention also provides an application programming interface (API) determining device, comprising:
[0027] A construction module is used to construct at least one cardinality tree based on at least one proxy path and the proxy API identifier corresponding to each proxy path; the cardinality tree includes each proxy path and the proxy API identifier corresponding to each proxy path;
[0028] The first determining module is configured to, upon receiving an API request, determine a target proxy API identifier based on each of the cardinality trees and the request information included in the API request; wherein the request information is used to request access to the target API;
[0029] The second determining module is used to determine the target API based on the target proxy API identifier and the rule base; the rule base includes at least one path matching rule, and the path matching rule corresponds to the proxy API identifier.
[0030] The present invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the application programming interface (API) determination method as described above.
[0031] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the application programming interface (API) determination method as described above.
[0032] The present invention also provides a computer program product, including a computer program that, when executed by a processor, implements the application programming interface (API) determination method as described above.
[0033] The application programming interface (API) determination method provided by this invention constructs at least one cardinality tree based on at least one proxy path and the corresponding proxy API identifier for each proxy path. The cardinality tree includes each proxy path and its corresponding proxy API identifier. Upon receiving an API request, the method determines the target proxy API identifier based on the cardinality trees and the request information included in the API request. Then, it determines the target API based on the target proxy API identifier and the proxy API identifiers corresponding to multiple path matching rules included in the rule base. Because cardinality trees offer high query performance, the target proxy API identifier can be quickly determined based on the cardinality trees and the request information included in the API request. Furthermore, the target API is determined based on the target proxy API identifier and the rule base, improving the performance of API lookup and enhancing API matching efficiency. Attached Figure Description
[0034] To more clearly illustrate the technical solutions in this invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0035] Figure 1 This is one of the flowcharts illustrating the method for determining the application programming interface (API) provided by this invention;
[0036] Figure 2 This is the second flowchart illustrating the method for determining the application programming interface (API) provided by this invention;
[0037] Figure 3 This is a schematic diagram of the structure of the application programming interface (API) determining device provided by the present invention;
[0038] Figure 4 This is a schematic diagram of the structure of the electronic device provided by the present invention. Detailed Implementation
[0039] To make the objectives, technical solutions, and advantages of this invention clearer, the technical solutions of this invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this invention. All other embodiments obtained by those skilled in the art based on the embodiments of this invention without creative effort are within the scope of protection of this invention.
[0040] To facilitate a clearer understanding of the various embodiments of this application, some relevant knowledge will be introduced as follows.
[0041] Application Programming Interface (API) path: The API path is the interface address, that is, the access address exposed by the API.
[0042] Radix tree: Also known as a compressed trie, a radix tree is a more space-efficient trie. For each node in a radix tree, if the node is a child node, the child node is merged with the parent node.
[0043] The following is combined with Figures 1-2 The present invention describes a method for determining the application programming interface (API).
[0044] Figure 1 This is one of the flowcharts illustrating the method for determining the application programming interface (API) provided by this invention, such as... Figure 1 As shown, the method includes steps 101-103; wherein,
[0045] Step 101: Construct at least one cardinality tree based on at least one proxy path and the proxy API identifier corresponding to each proxy path; the cardinality tree includes each proxy path and the proxy API identifier corresponding to each proxy path.
[0046] It should be noted that the application programming interface (API) determination method provided by the present invention is applicable to API matching scenarios. The execution subject of the method can be an application programming interface (API) determination device, such as an electronic device, or a control module in the application programming interface (API) determination device for executing the application programming interface (API) determination method.
[0047] Specifically, after the component (application) starts, at least one proxy path and its corresponding proxy API identifier (ID) are added and saved to the database. This registers at least one predefined proxy path, which can also be dynamically registered or deleted. Upon the next application startup, the multiple proxy paths and their corresponding proxy API identifiers are reloaded from the database into memory. Multiple radix trees are then constructed based on these proxy paths and their corresponding API identifiers. Each radix tree includes multiple proxy paths and their respective proxy API identifiers, and each node in the radix tree has a priority; nodes with more child nodes have higher priority.
[0048] It should be noted that each proxy path includes request information, which includes request indication information and request path. The request indication information indicates the request method corresponding to the proxy path, such as a GET request, PUT request, or POST request. Therefore, the constructed multiple cardinality trees each correspond to a request method.
[0049] Step 102: Upon receiving an API request, determine the target proxy API identifier based on each of the cardinality trees and the request information included in the API request; wherein the request information is used to request access to the target API.
[0050] Specifically, when a user initiates an API request—that is, when a user requests access to a target API—the API request can be received. Upon receiving the API request, since it includes request information used to request access to the target API, this request information can be obtained by parsing the API request. Then, based on the constructed cardinality trees and the request information included in the API request, the target proxy API identifier can be found from multiple cardinality trees.
[0051] Step 103: Based on the target proxy API identifier and the rule base, determine the target API. The rule base includes at least one path matching rule, which corresponds to the proxy API identifier.
[0052] Specifically, the rule base includes at least one path matching rule, and each path matching rule corresponds to a proxy API identifier. Based on the target proxy API identifier and the rule base, proxy API identifiers that can match the target proxy API identifier can be identified, and the target API can then be determined based on the proxy API identifiers that match the target proxy API identifier.
[0053] The application programming interface (API) determination method provided by this invention constructs at least one cardinality tree based on at least one proxy path and the corresponding proxy API identifier for each proxy path. The cardinality tree includes each proxy path and its corresponding proxy API identifier. Upon receiving an API request, the method determines the target proxy API identifier based on the cardinality trees and the request information included in the API request. Then, it determines the target API based on the target proxy API identifier and the proxy API identifiers corresponding to multiple path matching rules included in the rule base. Because cardinality trees offer high query performance, the target proxy API identifier can be quickly determined based on the cardinality trees and the request information included in the API request. Furthermore, the target API is determined based on the target proxy API identifier and the rule base, improving the performance of API lookup and enhancing API matching efficiency.
[0054] Optionally, the specific implementation of step 101 above includes:
[0055] 1) Obtain at least one pre-configured proxy path and the proxy API identifier corresponding to each proxy path.
[0056] Specifically, multiple proxy paths from the database and their corresponding proxy API identifiers are loaded into memory, allowing the retrieval of each proxy path and its corresponding API identifier from memory. Each proxy path includes request information, which includes request indication information and a request path. The request indication information indicates the request method corresponding to the proxy path; for example, the request indication information indicates a GET, PUT, or POST request, and the request path is \A or \B. The request information also includes path parameters, for example, a path parameter of type :post.
[0057] 2) Parse each of the proxy paths to obtain the request information corresponding to each proxy path.
[0058] Specifically, since the proxy path includes request information, parsing each proxy path can yield the request information corresponding to each proxy path; the request information includes API decomposition information such as request method, request path, and path parameters.
[0059] 3) Construct each of the cardinality trees based on the request information and the proxy API identifier.
[0060] Specifically, a radix tree is generated from the request paths based on the request methods included in the request information. It should be noted that different request methods can generate different radix trees. The radix tree includes each proxy path and the corresponding proxy API identifier.
[0061] For example, the constructed radix tree is:
[0062]
[0063] This is equivalent to pre-defining / book / :ID_1, / bike / :ID_3, / tool / :post / :ID_5, / describe / :ID_6, / tool / :post / :ID_7, and / type / :ID_8, where :post is a placeholder, i.e., a path parameter.
[0064] Furthermore, both `book` and `bike` share a common parent node `b`, and parent node `b` does not have a corresponding proxy API identifier. Only leaf nodes (nodes with no child nodes) register proxy API identifiers. The actual proxy path for the API runs from the root node to the leaf nodes. The path search order is top-down and left-to-right. To quickly find as many proxy paths as possible, parent nodes with more child nodes have higher priority.
[0065] The application programming interface (API) determination method provided by this invention obtains at least one pre-configured proxy path and the proxy API identifier corresponding to each proxy path; parses each proxy path to obtain the request information corresponding to each proxy path; and constructs each radix tree based on each request information and each proxy API identifier. Since the radix tree has high query performance, the target proxy API identifier can be quickly determined based on the request information and each radix tree, thereby improving the performance of proxy API lookup and enhancing API matching efficiency.
[0066] Optionally, the request information includes request indication information and request path, and the specific implementation of step 103 above includes:
[0067] a) Based on the request indication information, select a target cardinal tree from each of the cardinal trees; the target cardinal tree corresponds to the request indication information.
[0068] Specifically, since the request information includes request indication information and request path, the target radix tree corresponding to the request method indicated by the request indication information is determined from multiple radix trees based on the request indication information. For example, if the request method is a GET request, and the three radix trees are the radix tree corresponding to the GET request, the radix tree corresponding to the PUT request, and the radix tree corresponding to the POST request, then the radix tree corresponding to the GET request is determined from the three radix trees as the target radix tree.
[0069] b) Determine the target proxy API identifier based on the target cardinality tree and the request path.
[0070] Specifically, the target proxy API identifier can be further determined based on the target cardinality tree and the request path.
[0071] Optionally, determining the target proxy API identifier based on the target cardinality tree and the request path includes:
[0072] Based on the request path, find the target proxy path corresponding to the request path in the target cardinality tree; and determine the proxy API identifier corresponding to the target proxy path as the target proxy API identifier.
[0073] Specifically, based on the determined target cardinality tree, since the target cardinality tree includes at least one proxy path and the proxy API identifier corresponding to each proxy path, the target proxy path corresponding to the request path is searched in the target cardinality tree according to the request path included in the request information, and the proxy API identifier corresponding to the target proxy path is determined as the target proxy API identifier.
[0074] It should be noted that during the search process, if the proxy path included in the target cardinality tree contains path parameters (i.e., placeholders), the path parameters will be further queried to obtain the proxy API identifier corresponding to the next node of the path parameters.
[0075] The application programming interface (API) determination method provided by this invention selects a target radix tree from various radix trees based on request indication information; the target radix tree corresponds to the request indication information. Since radix trees have high query performance, based on the request path, the target proxy path corresponding to the request path can be quickly found in the target radix tree, and the proxy API identifier corresponding to the target proxy path is determined as the target proxy API identifier, thereby improving the performance of proxy API lookup and enhancing API matching efficiency.
[0076] Optionally, the specific implementation of step 103 above includes:
[0077] 1) Match the target proxy API identifier with the proxy API identifier corresponding to each of the path matching rules included in the rule base.
[0078] Specifically, when registering at least one predefined proxy path, corresponding path matching rules are set for each proxy path, and the path matching rules are mapped to the corresponding proxy API identifiers for each proxy path. The path matching rules and their corresponding API identifiers are then stored in a rule base. These path matching rules can include functions such as going online, going offline, rate limiting, or blacklisting. Therefore, the determined target proxy API identifier can be matched against the API identifiers corresponding to each path matching rule in the rule base.
[0079] 2) If there is a match between the target proxy API identifier and each of the proxy API identifiers, the API corresponding to the proxy API identifier that matches the target proxy API identifier shall be determined as the target API.
[0080] Specifically, if the target proxy API identifier matches any of the proxy API identifiers, the API corresponding to the proxy API identifier that matches the target proxy API identifier is determined as the target API, and then the API request can be sent to the target API, which is the real API.
[0081] Furthermore, if the target proxy API identifier and the various API identifiers do not match, the reason for the mismatch will be returned.
[0082] The application programming interface (API) determination method provided by this invention matches a target proxy API identifier with the proxy API identifiers corresponding to each path matching rule included in the rule base. When a match exists between the target proxy API identifier and each proxy API identifier, the API corresponding to the proxy API identifier that matches the target proxy API identifier is determined as the target API. By separating the path matching rules included in the rule base from the radix tree, where the radix tree only stores the proxy API identifiers, the target proxy API identifier determined based on the radix tree can be associated with persistent path matching rules, reducing the data storage volume of the radix tree and thus improving the performance of proxy API lookup and enhancing API matching efficiency.
[0083] Optionally, the method further includes:
[0084] The path matching rule corresponding to the proxy API identifier that matches the target proxy API identifier is determined as the rule for the target API; if the rule is online, the API request is forwarded to the target API.
[0085] Specifically, the path matching rule corresponding to the proxy API identifier that matches the target proxy API identifier is determined as the target rule corresponding to the target proxy API identifier, and the target rule is determined as the rule for the target API corresponding to the target proxy API identifier. The target rule can be online, offline, rate limiting, or a blacklist, etc. If the target rule is online, the API request is forwarded to the target API, thus achieving control over the target API.
[0086] Figure 2 This is the second flowchart illustrating the method for determining the application programming interface (API) provided by this invention, as shown below. Figure 2 As shown, steps 201-211 are included; wherein,
[0087] Step 201: Obtain at least one pre-configured proxy path and the proxy API identifier corresponding to each proxy path.
[0088] Step 202: Parse each proxy path to obtain the request information corresponding to each proxy path; wherein, the request information includes request indication information and request path, and the request indication information is used to indicate the request method corresponding to the proxy path.
[0089] Step 203: Construct a radix tree corresponding to each request method based on the request information and the API identifier of each proxy.
[0090] Step 204: Obtain the API request. The API request includes request information, which includes request indication information and request path.
[0091] Step 205: Parse the API request to obtain the request indication information and request path corresponding to the API request.
[0092] Step 206: Select a target cardinal tree from multiple cardinal trees according to the request indication information corresponding to the API request; the target cardinal tree corresponds to the request indication information; according to the request path corresponding to the API request, find the target proxy path corresponding to the request path in the target cardinal tree, and determine the proxy API identifier corresponding to the target proxy path as the target proxy API identifier.
[0093] Step 207: Match the target proxy API identifier with the proxy API identifiers corresponding to each path matching rule included in the rule base. If the target proxy API identifier and each proxy API identifier match, proceed to step 208; if the target proxy API identifier and each proxy API identifier do not match, proceed to step 209.
[0094] Step 208: Determine the API corresponding to the proxy API identifier that matches the target proxy API identifier as the target API.
[0095] Step 209 returns the reason for the mismatch.
[0096] Step 210: Determine the path matching rule corresponding to the proxy API identifier that matches the target proxy API identifier as the rule for the target API.
[0097] Step 211: If the rule is online, forward the API request to the target API.
[0098] This invention also provides an application programming interface (API) determination system, which includes four modules: a path registration module, a path discovery module, a rules module, and a forwarding module. Path registration involves adding at least one proxy path and a corresponding proxy API identifier (ID) for each proxy path after the component (application) starts, and saving this information to a database. This registers at least one predefined proxy path, and can also be done dynamically. Upon the next application startup, the multiple proxy paths and their corresponding proxy API identifiers are reloaded from the database into memory. Multiple cardinality trees are then constructed based on these proxy paths and their corresponding proxy API identifiers. Each cardinality tree includes at least one proxy path and its corresponding proxy API identifier, and each node in the cardinality tree has a priority, with nodes containing more child nodes having higher priority.
[0099] The path discovery module, upon receiving an API request, takes the request information included in the API request, which includes request indication information and request path. Based on the request indication information, it selects a target cardinal tree from various cardinal trees, and searches for the target proxy path corresponding to the request path in the target cardinal tree. The proxy API identifier corresponding to the target proxy path is then identified as the target proxy API identifier. Leveraging the cardinal tree's ability to quickly search, the module improves the efficiency of finding the target proxy API identifier.
[0100] The rules module works by matching each proxy API identifier with corresponding path matching rules, such as online / offline, rate limiting, or blacklists / whitelists. When the rules module is executed, the component matches the target proxy API identifier with the proxy API identifiers corresponding to each path matching rule in the rule library. It then identifies the proxy API identifier that matches the target API identifier, determines the path matching rule corresponding to that matching proxy API identifier as the rule for the target API, and applies that rule to the target API.
[0101] The forwarding module, after passing through the rules module, forwards the API request to the target API when the rules are online.
[0102] The application programming interface (API) determination apparatus provided by the present invention is described below. The API determination apparatus described below and the API determination method described above can be referred to in correspondence.
[0103] Figure 3 This is a schematic diagram of the structure of the application programming interface (API) determining device provided by the present invention, as shown below. Figure 3 As shown, the application programming interface (API) determining device 300 includes a construction module 301, a first determining module 302, and a second determining module 303; wherein,
[0104] Construction module 301 is used to construct at least one cardinality tree based on at least one proxy path and the proxy API identifier corresponding to each proxy path; the cardinality tree includes each proxy path and the proxy API identifier corresponding to each proxy path;
[0105] The first determining module 302 is configured to, upon receiving an API request, determine a target proxy API identifier based on each of the cardinality trees and the request information included in the API request; wherein the request information is used to request access to the target API;
[0106] The second determining module 303 is used to determine the target API based on the target proxy API identifier and the rule base; the rule base includes at least one path matching rule, and the path matching rule corresponds to the proxy API identifier.
[0107] The application programming interface (API) determination device provided by this invention constructs at least one cardinality tree based on at least one proxy path and the corresponding proxy API identifier for each proxy path. The cardinality tree includes each proxy path and its corresponding proxy API identifier. Upon receiving an API request, it determines the target proxy API identifier based on the cardinality trees and the request information included in the API request. Then, it determines the target API based on the target proxy API identifier and the proxy API identifiers corresponding to multiple path matching rules included in the rule base. Because cardinality trees offer high query performance, the target proxy API identifier can be quickly determined based on the cardinality trees and the request information included in the API request. Furthermore, the target API is determined based on the target proxy API identifier and the rule base, improving the performance of API lookup and enhancing API matching efficiency.
[0108] Optionally, the construction module 301 is specifically used for:
[0109] Obtain at least one pre-configured proxy path and the proxy API identifier corresponding to each of the proxy paths;
[0110] Each of the proxy paths is parsed to obtain the request information corresponding to each proxy path;
[0111] Each cardinality tree is constructed based on the request information and the proxy API identifier.
[0112] Optionally, the first determining module 302 is specifically used for:
[0113] Based on the request indication information, a target cardinal tree is selected from each of the cardinal trees; the target cardinal tree corresponds to the request indication information.
[0114] Based on the target cardinality tree and the request path, the target proxy API identifier is determined.
[0115] Optionally, the first determining module 302 is specifically used for:
[0116] Based on the request path, find the target proxy path corresponding to the request path in the target cardinality tree;
[0117] The proxy API identifier corresponding to the target proxy path is determined as the target proxy API identifier.
[0118] Optionally, the second determining module 303 is specifically used for:
[0119] The target proxy API identifier is matched with the proxy API identifier corresponding to each of the path matching rules included in the rule base;
[0120] If there is a match between the target proxy API identifier and each of the proxy API identifiers, the API corresponding to the proxy API identifier that matches the target proxy API identifier is determined as the target API.
[0121] Optionally, the application programming interface (API) determining device 300 further includes:
[0122] The second determining module is used to determine the path matching rule corresponding to the proxy API identifier that matches the target proxy API identifier as the rule of the target API;
[0123] The sending module is used to forward the API request to the target API when the rule is online.
[0124] Figure 4 This is a schematic diagram of the physical structure of an electronic device provided by the present invention, such as... Figure 4 As shown, the electronic device 400 may include a processor 410, a communications interface 420, a memory 430, and a communication bus 440, wherein the processor 410, the communications interface 420, and the memory 430 communicate with each other through the communication bus 440. The processor 410 may invoke logical instructions in the memory 430 to execute an application programming interface (API) determination method. This method includes: constructing at least one cardinality tree based on at least one proxy path and a proxy API identifier corresponding to each proxy path; the cardinality tree includes each proxy path and a proxy API identifier corresponding to each proxy path; upon receiving an API request, determining a target proxy API identifier based on each cardinality tree and request information included in the API request; wherein the request information is used to request access to the target API; and determining the target API based on the target proxy API identifier and a rule base; the rule base includes at least one path matching rule, and the path matching rule corresponds to the proxy API identifier.
[0125] Furthermore, the logical instructions in the aforementioned memory 430 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, essentially, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0126] On the other hand, the present invention also provides a computer program product, which includes a computer program that can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the application programming interface (API) determination method provided by the above methods. The method includes: constructing at least one cardinality tree based on at least one proxy path and proxy API identifiers corresponding to each proxy path; the cardinality tree includes each proxy path and the proxy API identifiers corresponding to each proxy path; upon receiving an API request, determining a target proxy API identifier based on each cardinality tree and request information included in the API request; wherein the request information is used to request access to the target API; determining the target API based on the target proxy API identifier and a rule base; the rule base includes at least one path matching rule, and the path matching rule corresponds to the proxy API identifier.
[0127] In another aspect, the present invention also provides a non-transitory computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements an application programming interface (API) determination method provided by the methods described above. This method includes: constructing at least one cardinality tree based on at least one proxy path and proxy API identifiers corresponding to each proxy path; the cardinality tree includes each proxy path and the proxy API identifiers corresponding to each proxy path; upon receiving an API request, determining a target proxy API identifier based on each cardinality tree and request information included in the API request; wherein the request information is used to request access to the target API; and determining the target API based on the target proxy API identifier and a rule base; the rule base includes at least one path matching rule, the path matching rule corresponding to the proxy API identifier.
[0128] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.
[0129] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.
[0130] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for determining an Application Programming Interface (API), characterized in that, include: Construct at least one radix tree based on at least one proxy path and the proxy API identifier corresponding to each proxy path; The radix tree includes each of the proxy paths and the proxy API identifier corresponding to each of the proxy paths; Upon receiving an API request, the target proxy API identifier is determined based on each of the cardinality trees and the request information included in the API request; wherein the request information is used to request access to the target API; The target API is determined based on the target proxy API identifier and the rule base; the rule base includes at least one path matching rule, which corresponds to the proxy API identifier. The step of constructing at least one radix tree based on at least one proxy path and the proxy API identifier corresponding to each proxy path includes: Obtain at least one pre-configured proxy path and the proxy API identifier corresponding to each of the proxy paths; Each of the proxy paths is parsed to obtain the request information corresponding to each proxy path; Based on the request information and the proxy API identifier, construct the radix tree. The request information includes request indication information and request path. Determining the target proxy API identifier based on each of the cardinality trees and the request information included in the API request includes: Based on the request indication information, a target cardinal tree is selected from each of the cardinal trees; the target cardinal tree corresponds to the request indication information. Based on the target cardinality tree and the request path, the target proxy API identifier is determined.
2. The method for determining the application programming interface (API) according to claim 1, characterized in that, The step of determining the target proxy API identifier based on the target cardinality tree and the request path includes: Based on the request path, find the target proxy path corresponding to the request path in the target cardinality tree; The proxy API identifier corresponding to the target proxy path is determined as the target proxy API identifier.
3. The method for determining the application programming interface (API) according to claim 1 or 2, characterized in that, The step of determining the target API based on the target proxy API identifier and rule base includes: The target proxy API identifier is matched with the proxy API identifier corresponding to each of the path matching rules included in the rule base; If there is a match between the target proxy API identifier and each of the proxy API identifiers, the API corresponding to the proxy API identifier that matches the target proxy API identifier is determined as the target API.
4. The method for determining the application programming interface (API) according to claim 3, characterized in that, The method further includes: The path matching rule corresponding to the proxy API identifier that matches the target proxy API identifier is determined as the rule for the target API; If the rule is online, the API request will be forwarded to the target API.
5. An application programming interface (API) determining device, characterized in that, include: The construction module is used to construct at least one radix tree based on at least one proxy path and the proxy API identifier corresponding to each of the proxy paths; The radix tree includes each of the proxy paths and the proxy API identifier corresponding to each of the proxy paths; The first determining module is configured to, upon receiving an API request, determine a target proxy API identifier based on each of the cardinality trees and the request information included in the API request; wherein the request information is used to request access to the target API; The second determining module is used to determine the target API based on the target proxy API identifier and the rule base; the rule base includes at least one path matching rule, and the path matching rule corresponds to the proxy API identifier; The building module is specifically used for: Each of the proxy paths is parsed to obtain the request information corresponding to each proxy path; Based on the request information and the proxy API identifier, construct the radix tree. The request information includes request indication information and a request path. The first determining module is specifically used for: Based on the request indication information, a target cardinal tree is selected from each of the cardinal trees; the target cardinal tree corresponds to the request indication information. Based on the target cardinality tree and the request path, the target proxy API identifier is determined.
6. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the application programming interface (API) determination method as described in any one of claims 1 to 4.
7. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the application programming interface (API) determination method as described in any one of claims 1 to 4.
8. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the application programming interface (API) determination method as described in any one of claims 1 to 4.
Citation Information
Patent Citations
Data transmission method, device and equipment and readable storage medium
CN113254233A