Network request response method, response device and application program interface gateway system

By building an application program interface gateway system in the OpenResty environment, and using script extension components to dynamically obtain the target server for server load balancing, the problem that the Resty-http library fails to effectively support back-end server load balancing in HTTP communication, improving the availability and scalability of the system.

CN120263790APending Publication Date: 2025-07-04BOE TECHNOLOGY GROUP CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510450783.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-10
Publication Date
2025-07-04

AI Technical Summary

Technical Problem

The existing Resty-http library fails to effectively support the load balancing of the backend servers during HTTP communication, resulting in the inability to reasonably allocate requests to multiple backend servers, resulting in excessive load on some servers and prolonged response time, which affects the scalability and high availability of the system.

Method used

By building an application program interface gateway system in the OpenResty environment, using script extension components to resolve network requests, dynamically obtain the target server for load balancing in the server, and generate response results through reverse proxy to the server cluster to achieve load balancing of the backend server.

Benefits of technology

It significantly improves the availability, scalability and service response efficiency of the server, simplifies the call logic, blocks the physical topology details of the backend cluster, and realizes the precise distribution of requested traffic.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120263790A_ABST
    Figure CN120263790A_ABST
Patent Text Reader

Abstract

The invention discloses a network request response method and device and an application program interface gateway system. The application program interface gateway system communicates with a client and a server, the application program interface gateway system is constructed based on OpenResty, the server is deployed with a server cluster, and the response method comprises the following steps: performing domain name resolution on a network request initiated by the client to obtain a resolution result; processing the analysis result through a script extension component to obtain a load-balanced target server in the server, and calling a server interface according to the target server; judging whether the processing is passed or not according to a calling result of the server interface; under the condition that the processing is passed, reversely proxy to the server cluster to enable the server cluster to respond to the network request to generate a first response result; and feeding back the first response result to the client. In this way, the application program interface gateway system supports load balancing when calling the back-end service.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer communication technologies, and particularly to a method for responding to network requests, a response device, and an application programming interface gateway system. Background Art

[0002] In network development, when certain application scenarios initiate HTTP requests from a Web or terminal device, the business logic needs to be processed by a script extension component and then reverse-proxied to the corresponding backend service. When the script extension component processes the business logic, it calls the application programming interface (API) of Resty-http to call the backend service.

[0003] However, currently, Resty-http only focuses on providing basic HTTP communication capabilities and does not support load balancing of backend servers. As a result, requests cannot be reasonably distributed to multiple backend servers, causing some servers to be overloaded, resulting in performance bottlenecks, extended response times, and other problems, which is not conducive to the scalability and high availability of the system. Therefore, how to support load balancing of backend servers when using Resty-Http has become an urgent problem to be solved. Summary of the Invention

[0004] In view of this, this application provides a method for responding to network requests, a response device, and an application programming interface gateway system.

[0005] The response method according to the embodiments of this application is used in an application programming interface gateway system. The application programming interface gateway system communicates with a client and a server. The application programming interface gateway system is built based on OpenResty, and a server cluster is deployed on the server side. The response method includes:

[0006] Performing domain name resolution on the network request initiated by the client to obtain a resolution result;

[0007] Processing the resolution result through a script extension component to obtain a target server with load balancing in the server side, and calling a server-side interface according to the target server;

[0008] Judging whether the processing passes according to the call result of the server-side interface;

[0009] In the case where the processing passes, reverse-proxying to the server cluster so that the server cluster responds to the network request to generate a first response result; and

[0010] Feeding back the first response result to the client.

[0011] In some embodiments, processing the resolution result through a script extension component includes:

[0012] Determine the type of the parsing result;

[0013] When the type of the parsing result is at least one of a picture resource request, an audio resource request, or a video resource request, obtain the target server for load balancing in the server through the load balancing plugin;

[0014] Use the server address of the target server as the address prefix of the server interface through the remote call tool to call the server interface.

[0015] In some embodiments, obtaining the target server for load balancing in the server through the load balancing plugin includes:

[0016] Obtain the server information of the server, where the server information includes addr, backup, fail_timeout, max_fails;

[0017] Determine the target server in the server information based on a preset allocation algorithm, where the target server is used to implement the network request.

[0018] In some embodiments, obtaining the server information of the server includes:

[0019] Determine whether the server information is included in the cache;

[0020] When the server information exists in the cache, obtain the server information in the cache.

[0021] In some embodiments, obtaining the server information of the server further includes:

[0022] When the server information does not exist in the cache, obtain the server cluster list of the server;

[0023] Traverse the server cluster list to obtain the server set in the current server group;

[0024] Traverse the server set to obtain the server information of each server in the server set;

[0025] Record the server information of each server in the cache.

[0026] In some embodiments, determining the target server in the server information based on a preset allocation algorithm, where the target server is used to implement the network request, includes:

[0027] Select the target information from the server information based on a preset allocation algorithm, where the target information is one of the server information;

[0028] Determine the target server according to the target information.

[0029] In some embodiments, the preset allocation algorithm includes at least one of a polling algorithm, a weight algorithm, a random algorithm, or a hash algorithm.

[0030] In some embodiments, determining the target server according to the target information includes:

[0031] Determine whether the corresponding server of the target information is down;

[0032] In the case where the server corresponding to the target information is not down, use the server corresponding to the target information as the target server; or

[0033] In the case where the server corresponding to the target information is down, delete the target information.

[0034] In some embodiments, the call result includes one of no response from the server-side interface, no access permission to the current resource, or having access permission. Judging whether the processing passes according to the call result of the server-side interface includes:

[0035] In the case where the call result is having access permission, judge that the processing passes; or

[0036] In the case where the call result is no response from the server-side interface or no access permission to the current resource, judge that the processing does not pass.

[0037] In some embodiments, the response method further includes:

[0038] In the case where the processing does not pass, generate a second response result according to the call result of the server-side interface;

[0039] Feedback the second response result to the client.

[0040] In some embodiments, the network request is an HTTP request, and the remote call tool includes Resty-http.

[0041] The application program interface gateway system according to the embodiments of the present application includes a processor and a memory. The memory stores a computer program. When the computer program is executed by the processor, the processor executes the response method.

[0042] In the response method, response device, and application program interface gateway system according to the embodiments of the present application, the script extension component processes the network request after domain name resolution, and dynamically obtains the target server of the available load balancer in the server during the processing, so as to call the server interface according to the target server, and in the case of successful processing, reverse proxy to the server cluster so that the server cluster responds to the network request to generate a response result. In this way, on the one hand, it realizes load balancing of the backend server when calling the server interface, significantly improving the availability, scalability, and service response efficiency of the server. On the other hand, compared with the traditional static configuration (i.e., using IP address or domain name address for the interface address) load balancing scheme, it significantly improves the system availability and scalability, and shields the physical topology details of the backend cluster, enabling the client to be unaware of the multi-node deployment architecture, simplifying the call logic, and realizing accurate distribution of request traffic.

[0043] Additional aspects and advantages of the present application will be given in part in the following description, become apparent in part from the following description, or be learned through the practice of the present application. Brief Description of the Drawings

[0044] The above and / or additional aspects and advantages of the present application will become apparent and be readily understood from the following description of the embodiments in conjunction with the accompanying drawings, where:

[0045] Figure 1 is a schematic flowchart of the response method for network requests in some embodiments of the present application;

[0046] Figure 2 is a schematic block diagram of the response device for network requests in some embodiments of the present application;

[0047] Figure 3 is a schematic diagram of the scenario for implementing the response method for network requests in some embodiments of the present application;

[0048] Figures 4 - 9 is a schematic flowchart of the response method for network requests in some embodiments of the present application. Detailed Embodiments

[0049] The embodiments of the present application will be described in detail below. The examples of the embodiments are shown in the accompanying drawings, where the same or similar reference numerals denote the same or similar elements or elements with the same or similar functions throughout. The embodiments described below with reference to the accompanying drawings are exemplary and are intended to explain the present application and should not be construed as limiting the present application.

[0050] In web development, when certain application scenarios initiate network requests from the network side or terminal devices, they need to process business logic through a script extension component and then reverse proxy to the corresponding backend services. The script extension component is a lightweight, efficient, and embeddable programming language script for other applications. With its concise syntax, flexible semantics, and powerful extension capabilities, it is widely used in multiple fields such as game development, web applications, and data processing to implement various logical functions and rapid prototyping. When the script extension component processes business logic, it involves calling the application programming interface (API) of Resty-http to call the backend service. Resty-http is a library for sending network requests in the Lua environment of OpenResty or Nginx. It provides a simple and efficient way to communicate via network requests, supports HTTP / 1.1 and HTTP / 2, and is very suitable for scenarios that need to interact with external application interfaces.

[0051] However, since Resty-http currently only focuses on providing basic HTTP communication capabilities and does not have built-in load balancing-related functional logic (such as not implementing load balancing algorithms, server list management, and health checks, etc.), the remote call tool does not support load balancing of backend servers (load balancing is a technology and strategy that evenly distributes network traffic or workloads across multiple servers, computers, or other resources, aiming to optimize resource utilization, improve system performance, enhance reliability, and fault tolerance). As a result, requests cannot be reasonably distributed to multiple backend servers, causing some servers to be overloaded, resulting in performance bottlenecks, extended response times, and other issues, which is not conducive to the scalability and high availability of the system.

[0052] In related technologies, when the application programming interface of Resty-http calls the backend service interface, the interface address can use the Internet Protocol address (IP address) to achieve load balancing of backend servers, or the interface address can use a domain name to achieve load balancing of backend servers.

[0053] In the solution where an IP address is used for the interface address, since Resty-http does not support load balancing of backend servers, only one gateway can be fixedly specified during the call. For example, when the script extension component in Nginx1 calls the backend service, gateway 1 is specified for the call, and the internal network IP is used. After obtaining the result, it is then reverse-proxied to the business system cluster according to the business scenario. There is a possibility that the specified gateway may be down. In this case, the business system cluster will not function, and thus load balancing cannot be achieved for the backend service deployed in a cluster. It is possible that the service being called has just gone down, resulting in the inability to use the function properly. In the solution where a domain name is used for the interface address, there is no need to fixedly specify a certain gateway in each Nginx. By using the domain name and then through domain name resolution, it reaches the Nginx cluster (combining multiple Nginx servers together in a specific way to form a set of servers that can work together to achieve functions such as high availability, load balancing, and performance expansion). The Nginx cluster performs load balancing to select the specified gateway, and then through the reverse proxy of the Nginx cluster to the specified gateway. However, the drawback of this solution is that using the domain name requires domain name resolution again, and then the Nginx cluster performs load balancing to select the specified gateway; and after two rounds of domain name resolution, it goes through the external network, resulting in low efficiency. Therefore, how to support load balancing of backend servers when using remote call tools has become an urgent problem to be solved currently.

[0054] In view of this, please refer to Figure 1 , an embodiment of the present application provides a method for responding to a network request, which is used for an application programming interface gateway system. The application programming interface gateway system communicates with a client and a server. The application programming interface gateway system is built based on OpenResty, and a server cluster is deployed on the server side. The response method includes:

[0055] 01: Perform domain name resolution on the network request initiated by the client to obtain a resolution result;

[0056] 02: Process the resolution result through a script extension component to obtain the target server for load balancing in the server side, and call the server side interface according to the target server;

[0057] 03: Determine whether the processing is passed according to the call result of the server side interface;

[0058] 04: In the case where the processing is passed, perform reverse proxy to the server cluster so that the server cluster responds to the network request to generate a first response result; and

[0059] 05: Feed back the first response result to the client.

[0060] Please refer to Figure 2, an embodiment of the present application provides a response device 10 for a network request, which is used in an application programming interface gateway system. The response device 10 includes a parsing module 11, a processing module 12, a judgment module 13, a reverse proxy module 14, and a feedback module 15. Among them, step 01 can be implemented by the parsing module 11, step 02 can be implemented by the processing module 12, step 03 can be implemented by the judgment module 13, step 04 can be implemented by the reverse proxy module 14, and step 05 can be implemented by the feedback module 15.

[0061] Or rather, the parsing module 11 can be used to perform domain name resolution on the network request initiated by the client to obtain a resolution result; the processing module 12 can be used to process the resolution result through a script extension component to obtain the target server of the load balancing in the server side, and call the server side interface according to the target server; the judgment module 13 can be used to judge whether the processing is passed according to the call result of the server side interface; the reverse proxy module 14 can be used to reverse proxy to the server cluster in the case that the processing is passed so that the server cluster responds to the network request to generate a first response result; the feedback module 15 can be used to return the first response result to the client.

[0062] The present application also provides an application programming interface gateway system, which includes a processor and a memory. The memory stores a computer program. When the computer program is executed by the processor, the processor implements the above response method. That is, the processor is used to perform domain name resolution on the network request initiated by the client to obtain a resolution result; and process the resolution result through a script extension component to obtain the target server of the load balancing in the server side, and call the server side interface according to the target server; the processor can also be used to judge whether the processing is passed according to the call result of the server side interface; and in the case that the processing is passed, reverse proxy to the server cluster so that the server cluster responds to the network request to generate a first response result; and feedback the first response result to the client.

[0063] In the method for responding to a network request, response device, and application programming interface gateway system of the present application, a script extension component processes the network request after domain name resolution, and dynamically obtains a target server of the available load balancer in the server during the processing, so as to call the server interface according to the target server, and in the case of successful processing, reverse proxy to the server cluster to enable the server cluster to respond to the network request to generate a response result. In this way, on the one hand, it realizes load balancing of the backend server when calling the server interface, significantly improving the availability, scalability, and service response efficiency of the server. On the other hand, compared with the traditional static configuration (i.e., using an IP address or domain name address for the interface address) load balancing scheme, it significantly improves the system availability and scalability, and shields the physical topology details of the backend cluster, making the client unaware of the multi-node deployment architecture, simplifying the call logic, and at the same time achieving precise distribution of the request traffic.

[0064] In some embodiments, the response device 10 may be a part of the application programming interface gateway system. Or rather, the application programming interface gateway system includes the response device 10.

[0065] In some embodiments, the response device 10 may be discrete components assembled in a certain way to have the aforementioned functions, or a chip in the form of an integrated circuit having the aforementioned functions, or a computer software code segment that makes a computer have the aforementioned functions when running on a computer.

[0066] In some embodiments, as hardware, the response device 10 may be independent or added as an additional peripheral component to the application programming interface gateway system. The response device 10 may also be integrated into the application programming interface gateway system. For example, when the response device 10 is a part of the application programming interface gateway system, the response device 10 may be integrated into the processor.

[0067] It should be noted that the network request may be an HTTP request. That is, the domain name of the HTTP request initiated by the client is resolved to obtain a resolution result. Among them, domain name resolution, also known as DNS resolution, is a process of converting a human-readable domain name into an IP address recognizable by a computer.

[0068] An application programming interface gateway system (API gateway system) is an intermediate layer service located between the client and the backend service. It is mainly responsible for receiving, processing, and forwarding the application programming interface requests (API requests) of the client to the backend service, providing a unified application programming interface entry for the client, hiding the complexity of the backend service, and at the same time comprehensively managing and controlling the requests and responses to ensure the security, reliability, and high performance of the system.

[0069] OpenResty is a high-performance network platform based on Nginx (a lightweight and high-performance Web server, reverse proxy server, and email (IMAP / POP3) proxy server) and Lua (a lightweight and efficient scripting programming language). It combines Nginx's event-driven model with Lua's lightweight scripting language and extends Nginx's functionality through a series of script extension components, enabling developers to easily implement high-performance Web applications, API gateways, microservices, etc. It performs excellently in handling high-concurrency and low-latency network requests and is widely used in the backend service architectures of Internet companies.

[0070] A server cluster refers to a computing system that connects multiple servers together through a network to work collaboratively to provide higher performance, availability, and scalability. A server-side interface (Application Programming Interface, API) is a set of programming interfaces provided by the server-side for external application programs. It defines a series of endpoints, request methods, request parameters, and response data formats, allowing different software to interact with the server-side through the network to achieve functions such as obtaining data and performing operations.

[0071] Please combine Figure 3 With that, the application programming interface gateway system acts as a proxy and communicates with the client and the server-side respectively. The application programming interface gateway system deploys an Nginx cluster. An Nginx cluster refers to a collection of multiple Nginx servers (lightweight and high-performance open-source Web servers) combined in a specific way to form a server set that can work collaboratively. The Nginx cluster consists of Web services - Nginx (i.e., OpenResty). For example, in some examples, the application programming interface gateway system can deploy Nginx1, Nginx2, and Nginx3.

[0072] The client can send network requests to the application programming interface gateway system through the WEB or terminal devices. The terminal devices can be Android operating systems or Windows operating systems. The server-side is deployed in a cluster and can include multiple gateways, multiple services, and other middleware. Among them, multiple gateways form a gateway cluster, and multiple services form a service cluster. In the server-side, the network requests reverse-proxied from the Nginx cluster in the application programming interface gateway system first reach the gateway and then are routed by the gateway to the corresponding business system.

[0073] Specifically, when a client initiates a network request, after domain name resolution, the network request reaches the Nginx cluster of the application programming interface gateway system. It should be noted that domain name resolution is a service that points a domain name to the IP of a website space, enabling people to conveniently access the website through the registered domain name. In the Nginx cluster, the network request after domain name resolution can be processed through a script extension component. The script extension component can include a remote call tool and a load balancing plugin. The remote call tool can be used within the script extension component to call the server-side interface. Moreover, when using the remote call tool to call the server-side interface, the target server for load balancing in the server-side can be obtained through the load balancing plugin. The target server is at least one in the server cluster, and the server-side interface is called based on the target server.

[0074] In this embodiment, the script extension component can be a Lua module, and the remote call tool can be Resty-http. Those skilled in the art can understand that the Lua module is a functional unit written based on the Lua language and can be loaded and used by other programs or systems. It encapsulates related functions, variables, data structures, etc., and provides them to the outside for calling through specific interfaces to achieve function extension, logic customization, or code reuse of the main program. It is widely used in fields such as game development, Web server (such as Nginx) extension, and embedded systems, bringing flexible and efficient script programming capabilities to these systems. Resty-http is a Lua library in the OpenResty ecosystem, which provides convenient HTTP client functions for Lua scripts in the OpenResty environment. That is to say, the network request after domain name resolution can be processed through the Lua module, and the server-side interface can be called through Resty-http. Moreover, when using the remote call tool to call the server-side interface, the target server for load balancing in the server-side can be obtained.

[0075] In the case where the script extension component successfully processes the network request after domain name resolution, the Nginx cluster performs reverse proxy to the server cluster on the server side, so that the server cluster responds to the network request and generates a first response result, and then the first response result is fed back to the client. In this way, load balancing is achieved when the remote call tool calls the server-side interface, and the performance is efficient.

[0076] Please refer to Figure 4 , in some embodiments, step 02 includes:

[0077] 021: Determine the type of the parsing result;

[0078] 022: When the type of the parsing result is at least one of a picture resource request, an audio resource request, or a video resource request, obtain the target server of the load balancing in the server through the load balancing plug-in;

[0079] 023: Use the server address of the target server as the address prefix of the server-side interface through the remote call tool to call the server-side interface.

[0080] Please combine with Figure 2 , in some embodiments, sub-steps 021-023 may be implemented by the processing module 12, or rather, the processing module 12 may be used to determine the type of the parsing result, and when the type of the parsing result is at least one of a picture resource request, an audio resource request, or a video resource request, the load balancing plug-in obtains the target server of the load balancing in the server, and uses the server address of the target server as the address prefix of the server-side interface through the remote call tool to call the server-side interface.

[0081] In some embodiments, the processor may be used to determine the type of the parsing result, and when the type of the parsing result is at least one of a picture resource request, an audio resource request, or a video resource request, the load balancing plug-in obtains the target server of the load balancing in the server, and uses the server address of the target server as the address prefix of the server-side interface through the remote call tool to call the server-side interface.

[0082] Specifically, the script extension component may include a remote call tool and a load balancing plug-in. Among them, the load balancing plug-in is used to obtain the server address of the target server of the load balancing in the server, and the remote call tool is used to use the server address of the target server as the address prefix of the server-side interface to call the server-side interface. In this embodiment, the remote call tool may be, but is not limited to, Resty-http (a library for sending network requests in the Lua environment of OpenResty or Nginx, which provides a simple and efficient way to perform network request communication), that is, use the server address of the target server as the address prefix of the server-side interface through Resty-http to call the server-side interface.

[0083] It can be understood that when the network request is to process picture, audio, and video requests, Nginx can dynamically intervene in the business logic before resource transmission through Lua processing, or dynamically return adapted resources according to request characteristics (such as device type, geographical location). This mode combines the high-efficiency static transmission ability of Nginx with the flexible logic extension of Lua, enabling the distribution of static resources to integrate dynamic business rules without relying on repeated processing by the backend service.

[0084] In addition, it should be noted that when the type of the parsing result is other requests other than picture resource requests, audio resource requests or video resource requests (such as text requests, form submission requests, application programming interface requests), it can be directly reverse proxied to the server cluster on the server side through Ngnix without being processed by the script extension component.

[0085] Please refer to Figure 5 , in some embodiments, sub-step 022 includes:

[0086] 0221: Obtain the server information of the server side, where the server information includes addr, backup, fail_timeout, and max_fails;

[0087] 0222: Determine the target server from the server information based on a preset allocation algorithm, where the target server is used to implement network requests.

[0088] Please combine with Figure 2 , in some embodiments, sub-steps 0221 and 0222 can be implemented by the processing module 12, or rather, the processing module 12 can be used to obtain the server information of the server side, where the server information includes addr, backup, fail_timeout, and max_fails; or determine the target server from the server information based on a preset allocation algorithm, where the target server is used to implement network requests.

[0089] In some embodiments, the processor can be used to obtain the server information of the server side, where the server information includes addr, backup, fail_timeout, and max_fails; or determine the target server from the server information based on a preset allocation algorithm, where the target server is used to implement network requests.

[0090] It should be noted that the server information of the server side refers to the server information of all servers in the server side. Addr refers to the server address, backup refers to the standby server, fail_timeout refers to the failure timeout time, and max_fails refers to the maximum number of failures. The server information of the server side can be obtained from the cache of the application programming interface gateway system or can be called through a function.

[0091] The preset allocation algorithm includes at least one of a round-robin algorithm, a weight algorithm, a random algorithm, or a hash algorithm. That is, when using a remote call tool to call the server API inside the script extension component, the load balancing plugin can use at least one of a round-robin algorithm, a weight algorithm, a random algorithm, or a hash algorithm to select a load-balanced server from the server side as the target server.

[0092] For example, in some examples, the preset allocation algorithm can be the round-robin algorithm. The load balancing plugin distributes requests to the servers on the server side in sequence, and selects the next server for each request. Suppose there are N servers and the index of the current request is i:

[0093] Server = (i mod N)

[0094] where Server is the target server and i is the index of the network request

[0095] Again, for example, in some examples, the preset allocation algorithm can be the weighted round-robin algorithm. The servers are configured with weights and requests are allocated according to the weight ratio. Suppose there are N servers with weights W1, W2,..., Wn and the index of the current request is i:

[0096] Server = weighted_round_robin(i)

[0097] Server is the target server, weighted_round_robin is the weighted round-robin algorithm, and i is the index of the current network request, representing the i-th server in the server list.

[0098] In a specific example, for instance, suppose there are three servers Server1, Server2, and Server3 with weights 3, 2, and 1 respectively. When using the weighted round-robin algorithm, the algorithm allocates requests according to the weight ratio. First, Server1 is selected 3 times, then Server2 is selected 2 times, and then Server3 is selected 1 time, thus completing one round of weighted round-robin. Then, the servers are selected in the same order and weight ratio for the next round, and so on, to achieve balanced allocation of requests among servers with different weights.

[0099] Please refer to Figure 6 , in some embodiments, sub-step 0221 includes:

[0100] 02211: Determine whether the server information of the server side is included in the cache;

[0101] 02212: When the server information exists in the cache, obtain the server information in the cache.

[0102] Please refer to Figure 2 , in some embodiments, steps 02211 and 02212 can be implemented by the processing module 12, or rather, the processing module 12 can be used to determine whether the server information of the server side is included in the cache; when the server information exists in the cache, obtain the server information in the cache.

[0103] In some embodiments, the processor may be used to determine whether the server information of the server is included in the cache; in the case where the server information exists in the cache, obtain the server information in the cache.

[0104] In this way, by obtaining the server information in the cache, subsequent network requests can be allocated to the target server according to a preset allocation algorithm.

[0105] Please further refer to Figure 6 , in some embodiments, sub-step 0221 further includes:

[0106] 02213: In the case where the server information does not exist in the cache, obtain the server cluster list of the server side;

[0107] 02214: Traverse the server cluster list to obtain the server set in the current server group;

[0108] 02215, traverse the server set to obtain the server information of each server in the server set;

[0109] 02216, record the server information of each server in the cache.

[0110] Please combine with Figure 2 , in some embodiments, steps 02213 - 02216 may be implemented by the processing module 12, or rather, the processing module 12 may be used to obtain the server cluster list of the server side in the case where the server information does not exist in the cache; traverse the server cluster list to obtain the server set in the current server group; traverse the server set to obtain the server information of each server in the server set; record the server information of each server in the cache.

[0111] In some embodiments, the processor may be used to obtain the server cluster list of the server side in the case where the server information does not exist in the cache; traverse the server cluster list to obtain the server set in the current server group; traverse the server set to obtain the server information of each server in the server set; record the server information of each server in the cache.

[0112] Specifically, when the server information does not exist in the cache, the function get_upstreams of the Lua-upstream-Nginx-module library is called to obtain the server cluster list of the server side. It can be understood that the Lua-upstream-Nginx-module library is an Nginx module (a component that extends the functions of the Nginx server), which allows the use of script extension components for dynamic server selection and request scheduling during the upstream stage of Nginx (the process of Nginx interacting with the upstream server). get_upstreams is usually a function or method used in an environment related to load balancing or server clusters to obtain relevant information about upstream servers.

[0113] In step 0214, the currently obtained server cluster name can be assigned to the temporary variable upstream_name_tmp, and the get_servers function of the Lua-upstream-Nginx-module library (a function customized by the developer to obtain server-related information) is called to obtain all server sets under the current server group upstream_name_tmp.

[0114] After obtaining the server set, the server set can be traversed, that is, polling is performed on the server set to obtain the detailed information of each server. After the traversal of the server set is completed, the server cluster list can be traversed again until the traversal is completed. After the traversal is completed, each server information is recorded in the cache. In this way, the cache contains server information, so that subsequent network requests can be allocated to the target server according to the preset allocation algorithm.

[0115] Please refer to Figure 8 , in some embodiments, sub-step 0222 includes:

[0116] 02221: Select target information from the server information based on a preset allocation algorithm, where the target information is one of the server information;

[0117] 02222: Determine whether the corresponding server of the target information is down;

[0118] 02223: In the case where the server corresponding to the target information is not down, use the server corresponding to the target information as the target server; or

[0119] 02224: In the case where the server corresponding to the target information is down, delete the target information.

[0120] Please combine with Figure 2, in some embodiments, steps 02221 - 02224 can be implemented by the processing module 12. That is to say, the processing module 12 can be used to select target information from the server information based on a preset allocation algorithm, where the target information is one of the server information; determine whether the corresponding server of the target information is down; in the case where the server corresponding to the target information is not down, use the server corresponding to the target information as the target server; or in the case where the server corresponding to the target information is down, delete the target information.

[0121] In some embodiments, the processor can be used to select target information from the server information based on a preset allocation algorithm, where the target information is one of the server information; determine whether the corresponding server of the target information is down; in the case where the server corresponding to the target information is not down, use the server corresponding to the target information as the target server; or in the case where the server corresponding to the target information is down, delete the target information.

[0122] It should be noted that in step 02224, in the case where the server corresponding to the target information is down, after deleting the target information from the server information, steps 02211 - 02223 can be performed again to obtain the target server.

[0123] In this way, the situation of the selected target server being down is avoided, ensuring the load balancing when the remote call tool calls the server - side interface.

[0124] Please refer to Figure 8 , in some embodiments, the call result includes one of the server - side interface having no response, having no access permission to the current resource, or having access permission. Step 03 includes:

[0125] 031: In the case where the call result is having access permission, determine that the processing is passed; or

[0126] 032: In the case where the call result is the server - side interface having no response or having no access permission to the current resource, determine that the processing is not passed.

[0127] Please combine with Figure 2 , in some embodiments, sub - steps 031 and 032 can be implemented by the judgment module 13. That is to say, the judgment module 13 can be used to determine that the processing is passed in the case where the call result is having access permission; or determine that the processing is not passed in the case where the call result is the server - side interface having no response or having no access permission to the current resource.

[0128] In some embodiments, the processor can be used to determine that the processing is passed in the case where the call result is having access permission; or determine that the processing is not passed in the case where the call result is the server - side interface having no response or having no access permission to the current resource.

[0129] In this way, it is determined whether the script extension component processes the parsing result successfully through the call result of the client API, and then the corresponding response result can be fed back to the client, so that the client can timely understand the situation of the network request.

[0130] Please refer to Figure 9 , in some embodiments, the response method further includes:

[0131] 06: In the case where the processing fails, generate a second response result according to the call result of the server interface;

[0132] 07: Feed back the second response result to the client.

[0133] In some embodiments, the response device further includes a generation module 16. Step 06 can be implemented by the generation module 16, and step 07 can be implemented by the feedback module 15. Or rather, the generation module 16 can be used to generate a second response result according to the call result of the server interface in the case where the processing fails; the feedback module 15 can be used to feed back the second response result to the client.

[0134] In some embodiments, the processor can be used to generate a second response result according to the call result of the server interface in the case where the processing fails; and feed back the second response result to the client.

[0135] Specifically, in the case where the processing fails, if the call result is that the server interface has no response, the second response result can be that the server interface has no response. If the client has no access right to the current resource, the second response result can be a code indicating that the client has no resource access right.

[0136] In this way, the client can timely understand the call result of the server interface according to the second response result.

[0137] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the processes or functions described in the embodiments of the present application are generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center in a wired manner (such as coaxial cable, optical fiber, digital subscriber line (DSL)) or a wireless manner (such as infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server or a data center that includes one or more integrated available media. The available medium can be a magnetic medium (such as a floppy disk, a hard disk, or a magnetic tape), an optical medium (such as a digital video disc (DVD)), or a semiconductor medium (such as a solid-state disk (SSD)), etc.

[0138] Those of ordinary skill in the art will realize that the units and algorithm steps of the examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or in a combination of computer software and electronic hardware. Whether these functions are executed in hardware or software depends on the specific application and design constraints of the technical solution. A professional person can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of this application.

[0139] In several embodiments provided in the present application, it should be understood that the disclosed systems, devices, and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of the units is only a logical function division, and there can be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the displayed or discussed couplings or direct couplings or communication connections to each other can be through some interfaces, and the indirect couplings or communication connections of the devices or units can be in an electrical, mechanical, or other form.

[0140] In addition, in each embodiment of the present application, each functional unit can be integrated into one processing unit, can also exist physically alone for each unit, or two or more units can be integrated into one unit.

[0141] As described above, it is only the specific implementation manner of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art within the technical scope disclosed by the present application can easily think of changes or substitutions, and all should be covered within the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the said claims.

Claims

1. A response method for network requests, used in an application programming interface gateway system, characterized in that The application programming interface gateway system communicates with the client and the server. The application programming interface gateway system is built based on OpenResty. The server deploys a server cluster. The response method includes: Perform domain name resolution on the network request initiated by the client to obtain a resolution result; Process the resolution result through a script extension component to obtain the target server of the load balancer in the server, and call the server interface according to the target server; Judge whether the processing passes according to the call result of the server interface; In the case where the processing passes, reverse proxy to the server cluster so that the server cluster responds to the network request to generate a first response result; and Feedback the first response result to the client.

2. The response method according to claim 1, characterized in that, Processing the resolution result through a script extension component includes: Determine the type of the resolution result; In the case where the type of the resolution result is at least one of a picture resource request, an audio resource request, or a video resource request, obtain the target server of the load balancer in the server through a load balancing plugin; Use the server address of the target server as the address prefix of the server interface through a remote call tool to call the server interface.

3. The response method according to claim 2, characterized in that Obtaining the target server of the load balancer in the server through a load balancing plugin includes: Obtain the server information of the server, and the server information includes addr, backup, fail_timeout, max_fails; Determine a target server from the server information based on a preset allocation algorithm, and the target server is used to implement the network request.

4. The response method according to claim 3, characterized in that, Obtaining the server information of the server includes: Judge whether the server information of the server is included in the cache; In the case where the server information exists in the cache, obtain the server information in the cache.

5. The response method according to claim 4, characterized in that, Obtaining the server information of the server further includes: In the case where the server information does not exist in the cache, obtain the server cluster list of the server; Traverse the server cluster list to obtain the server set in the current server group; Traverse the server set to obtain the server information of each server in the server set; Record each server information in the cache.

6. The response method according to claim 3, wherein Determining a target server from the server information based on a preset allocation algorithm, and the target server is used to implement the network request, includes: Select target information from the server information based on a preset allocation algorithm, and the target information is one of the server information; Determine the target server according to the target information.

7. The response method according to claim 6, characterized in that The preset allocation algorithm includes at least one of a polling algorithm, a weight algorithm, a random algorithm, or a hash algorithm.

8. The response method according to claim 6, characterized in that Determining the target server according to the target information includes: Determine whether the server corresponding to the target information is down; In the case where the server corresponding to the target information is not down, use the server corresponding to the target information as the target server; or In the case where the server corresponding to the target information is down, delete the target information.

9. The response method according to claim 1, wherein The call result includes one of no response from the server-side interface, no access permission to the current resource, or having access permission. Determining whether the processing passes according to the call result of the server-side interface includes: When the call result is having access permission, determining that the processing passes; or When the call result is no response from the server-side interface or no access permission to the current resource, determining that the processing does not pass.

10. The response method according to claim 9, wherein The response method further includes: When the processing does not pass, generating a second response result according to the call result of the server-side interface; Feeding back the second response result to the client.

11. The response method according to claim 2, characterized in that, The network request is an HTTP request, the script extension component includes a Lua module, and the remote call tool includes Resty-http.

12. A response device for network requests, for an application programming interface gateway system, characterized in that, The application programming interface gateway system communicates with the client and the server. The application programming interface gateway system is built based on OpenResty. The server-side is deployed with a server cluster. The response device includes: A parsing module for performing domain name parsing on the network request initiated by the client to obtain a parsing result; A processing module for processing the parsing result through a script extension component to obtain the target server of the load balancing in the server-side, and calling the server-side interface according to the target server; A judging module for judging whether the processing passes according to the call result of the server-side interface; A reverse proxy module for, when the processing passes, reverse proxying to the server cluster so that the server cluster responds to the network request to generate a first response result; and A feedback module for returning the first response result to the client.

13. An application programming interface gateway system, characterized in that, It includes a processor and a memory. The processor stores a computer program. When the computer program is executed by the processor, the processor implements the response method according to any one of claims 1-11.