Request processing method and device
By building interface objects and determining the call order dependencies of requests, the problems of flexibility and inefficiency in the prior art are solved, and more efficient and automated request processing are achieved.
Patent Information
- Application Number
- CN202510530672.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-25
- Publication Date
- 2025-07-18
AI Technical Summary
The prior art has poor flexibility, low efficiency when processing multiple requests, and requires additional code writing to process business data dependencies.
Build an interface object, use the incoming parameters of the associated request function to determine the request's call order dependency, and call the send request function based on this order dependency to achieve the response data acquisition of multiple requests.
Improves flexibility and versatility in handling multiple requests, and improves the efficiency and automation of handling requests.
Smart Images

Figure CN120343097A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of Internet technologies, and in particular, to a method and an apparatus for processing requests. Background Art
[0002] In various service scenarios of Internet applications, requests need to be sent to multiple different network resource addresses, and various response data returned from the multiple network resource addresses are used as service data.
[0003] For the situation where requests need to be sent to multiple different network resource addresses and response data is obtained for the same service scenario, existing methods usually send each request independently and obtain the response data of the request; for the service data dependency relationship of multiple requests, code for processing the service data dependency relationship needs to be written additionally; existing methods have problems of poor flexibility and low efficiency when processing multiple requests. Summary of the Invention
[0004] In view of this, embodiments of the present invention provide a method and an apparatus for processing requests, which can construct interface objects for multiple requests, determine the call order dependency relationship of sending each request by using the input parameters of the associated request functions included in the set interface objects, and based on the call order dependency relationship, call the send request functions of each request to send requests, and then determine the response data of multiple requests; the embodiments of the present invention improve the flexibility and generality of processing multiple requests, and improve the efficiency and automation degree of processing requests.
[0005] To achieve the above object, according to one aspect of the embodiments of the present invention, there is provided a method for processing requests, characterized by including: receiving multiple requests, and constructing interface objects for each request; wherein, the interface object includes an associated request function and a send request function; obtaining the call order between any two adjacent requests among the multiple requests, and setting the interface object of the subsequent request among the two adjacent requests as the input parameter of the associated request function of the prior request; determining the call order dependency relationship of the send request functions of each request according to the input parameters of the associated request functions of each request; and based on the call order dependency relationship, calling the send request functions of each request to send requests, and determining the response data of multiple requests.
[0006] Optionally, calling the send request functions corresponding to each request to send requests includes: in response to sending requests in a concurrent manner, using multi-threading to concurrently execute the step of calling the send request functions corresponding to each request to send requests based on the call order dependency relationship.
[0007] Optionally, for any current request, the interface object also includes: an adjacent subsequent request object, an adjacent subsequent request object array, or one or more thereof; setting the interface object of the subsequent request between two adjacent requests as an input parameter of the associated request function of the prior request, including: in the case where there is one adjacent subsequent request for the current request, setting the adjacent subsequent request object corresponding to the adjacent subsequent request as an input parameter of the associated request function of the current request; in the case where there are multiple adjacent subsequent requests in parallel for the current request, using the adjacent subsequent request object array to store the adjacent subsequent request objects of the multiple adjacent subsequent requests, and setting the adjacent subsequent request object array as an input parameter of the associated request function of the current request.
[0008] Optionally, based on the calling order dependency, calling the sending request function of each request to send the request, including: for any current request, according to the calling order dependency, when it is determined that the current request has an adjacent prior request, obtaining the prior response data of the adjacent prior request; determining the associated parameters of the current request according to the prior response data, and calling the sending request function of the current request based on the associated parameters.
[0009] Optionally, the associated parameters of the request are determined according to the prior response data, and the send request function of the request is called based on the associated parameters, including: when it is determined that the current request has multiple parallel adjacent prior requests, obtaining the prior response data of each adjacent prior request; determining the associated parameters of the current request in combination with each prior response data, so as to call the send request function of the current request based on the associated parameters.
[0010] Optionally, based on the calling order dependency, calling the sending request function of each request to send the request, including: for any current request, according to the calling order dependency, when determining that the current request has an adjacent subsequent request; obtaining the current request's own response data; determining the associated parameters of the adjacent subsequent request based on the own response data, so as to call the sending request function of the adjacent subsequent request based on the associated parameters.
[0011] Optionally, determining the associated parameters of the adjacent subsequent request according to the own response data includes: when it is determined that the request has multiple adjacent subsequent requests in parallel; determining the associated parameters of each adjacent subsequent request according to the own response data.
[0012] Optionally, based on the calling order dependency, calling the sending request function of each request to send the request, including: for any current request, according to the calling order dependency, when determining that the current request has an adjacent prior request and an adjacent subsequent request; obtaining the prior response data of the adjacent prior request and the current request's own response data; determining the associated parameters of the adjacent subsequent request in combination with the prior response data and the current request's own response data, and calling the sending request function of the adjacent subsequent request based on the associated parameters.
[0013] To achieve the above object, according to a second aspect of an embodiment of the present invention, a device for processing a request is provided, characterized in that it includes: a request receiving module, an association determining module and a request sending module; wherein,
[0014] A request receiving module is used to receive multiple requests and construct an interface object for each request; wherein the interface object includes an association request function and a send request function;
[0015] Determine the association module, used to obtain the calling order between any two adjacent requests in the multiple requests, set the interface object of the later request in the two adjacent requests as the input parameter of the association request function of the earlier request, and determine the calling order dependency of the sending request function of each request according to the input parameter of the association request function of each request;
[0016] The sending request module is used to call the sending request function of each request to send the request based on the calling sequence dependency, and determine the response data of multiple requests.
[0017] Optionally, the device for processing requests is used to call the sending request function corresponding to each request to send the request, including: in response to sending the request in a concurrent manner, using multi-threaded concurrent execution to call the sending request function corresponding to each request based on a calling order dependency to send the request.
[0018] Optionally, for the device for processing requests, for any current request, the interface object also includes: an adjacent subsequent request object, an adjacent subsequent request object array, or one or more thereof; setting the interface object of the subsequent request between two adjacent requests as an input parameter of the associated request function of the prior request, including: in the case where there is one adjacent subsequent request for the current request, setting the adjacent subsequent request object corresponding to the adjacent subsequent request as an input parameter of the associated request function of the current request; in the case where there are multiple parallel adjacent subsequent requests for the current request, using an adjacent subsequent request object array to store the adjacent subsequent request objects of the multiple adjacent subsequent requests, and setting the adjacent subsequent request object array as an input parameter of the associated request function of the current request.
[0019] Optionally, the device for processing requests is used to call the send request function of each request to send the request based on the calling order dependency, including: for any current request, according to the calling order dependency, when it is determined that the current request has an adjacent previous request, obtaining the previous response data of the adjacent previous request; determining the associated parameters of the current request based on the prior response data, and calling the send request function of the current request based on the associated parameters.
[0020] Optionally, a device for processing requests, which is configured to determine the associated parameters of a request according to prior response data and call the send request function of the request based on the associated parameters, includes: when it is determined that the current request has multiple adjacent prior requests arranged in parallel, obtaining the prior response data of each adjacent prior request; combining the prior response data of each adjacent prior request to determine the associated parameters of the current request, so as to call the send request function of the current request based on the associated parameters.
[0021] Optionally, a device for processing requests, which is configured to call the send request functions of each request to send requests based on the call order dependency, includes: for any current request, according to the call order dependency, when it is determined that the current request has an adjacent subsequent request; obtaining the self-response data of the current request; determining the associated parameters of the adjacent subsequent request according to the self-response data, so as to call the send request function of the adjacent subsequent request based on the associated parameters.
[0022] Optionally, a device for processing requests, which is configured to determine the associated parameters of an adjacent subsequent request according to the self-response data, includes: when it is determined that the request has multiple adjacent subsequent requests arranged in parallel; determining the associated parameters of each adjacent subsequent request according to the self-response data.
[0023] Optionally, a device for processing requests, which is configured to call the send request functions of each request to send requests based on the call order dependency, includes: for any current request, according to the call order dependency, when it is determined that the current request has an adjacent prior request and an adjacent subsequent request; obtaining the prior response data of the adjacent prior request and the self-response data of the current request; combining the prior response data and the self-response data to determine the associated parameters of the adjacent subsequent request, and calling the send request function of the adjacent subsequent request based on the associated parameters.
[0024] To achieve the above object, according to the third aspect of the embodiments of the present invention, an electronic device for processing requests is provided, which is characterized by including: one or more processors; a storage device for storing one or more programs, when the one or more programs are executed by the one or more processors, enabling the one or more processors to implement any of the methods in the above method for processing requests.
[0025] To achieve the above object, according to the fourth aspect of the embodiments of the present invention, a computer-readable medium is provided, on which a computer program is stored, and is characterized in that when the program is executed by a processor, it implements any of the methods in the above method for processing requests.
[0026] To achieve the above object, according to the fifth aspect of the embodiments of the present invention, a computer program product is provided, including a computer program, and is characterized in that when the computer program is executed by a processor, it implements any of the methods in the above method for processing requests.
[0027] One embodiment of the above invention has the following advantages or beneficial effects: It can construct interface objects for multiple requests, determine the call order dependency relationships of each request's sending based on the input parameters of the associated request functions included in the set interface objects, and based on the call order dependency relationships, call the sending request functions of each request to send requests, and determine the required associated parameters for the adjacent subsequent requests according to the response data, thereby determining the response data of multiple requests; The embodiment of the present invention improves the flexibility and generality of processing multiple requests, and improves the efficiency and automation degree of processing requests.
[0028] The further effects of the above non-conventional optional manner will be described below in conjunction with the specific embodiments. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] The drawings are used to better understand the present invention and do not constitute an improper limitation to the present invention. Among them:
[0030] Figure 1 is a schematic flowchart of a method for processing requests provided by an embodiment of the present invention;
[0031] Figure 2A is a schematic structural diagram of the call order dependency relationship between requests provided by an embodiment of the present invention;
[0032] FIG. 2B is a schematic flowchart of determining the call order dependency relationship of multiple requests provided by an embodiment of the present invention;
[0033] Figure 3 is a schematic flowchart of a method for processing requests provided by an embodiment of the present invention;
[0034] Figure 4 is a schematic structural diagram of a device for processing requests provided by an embodiment of the present invention;
[0035] FIG. 5 is an exemplary system architecture diagram to which the embodiment of the present invention can be applied;
[0036] Figure 6 is a schematic structural diagram of a computer system of a terminal device or a server suitable for implementing the embodiment of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0037] The following describes exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, and they should be considered merely exemplary. Therefore, those of ordinary skill in the art should recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description below omits the description of well-known functions and structures.
[0038] In the description of the embodiments of the present invention, for example, multiple requests are request A, request B, and request C; assuming that the call order dependency relationship of these three requests is: request A -> request B -> request C; then request A is the adjacent prior request of request B, and request B is the adjacent subsequent request of request A; similarly, request B is the adjacent prior request of request C, and request C is the adjacent subsequent request of request B.
[0039] As Figure 1 shown, an embodiment of the present invention provides a method for processing requests, and the method may include the following steps:
[0040] Step S101: Receive multiple requests and construct interface objects for each request; wherein, the interface object includes an associated request function and a send request function.
[0041] Specifically, in the embodiments of the present invention, multiple requests belong to the same type of business scenario; for example: for the test scenario of the API (Application Programming Interface), testing needs to simulate diverse request scenarios, by using different combinations of request parameters, request header settings, and different request orders to be set, in order to verify the stability, correctness, and compatibility of the API interface; and for the scenario of downloading content, the requirement is to download the video with the highest playback volume of the creator xyz on the ABC website. For example, its associated requests are: request A -> request B -> request C, where the request resource address of request A is the homepage of the creator xyz. After obtaining the response data result according to request A, sort by playback volume and take the first one in the homepage video list, and then send the page address of the first-ranked video to request B. After request B obtains the video page address, it parses it to obtain the video stream address. Request C starts to download the video according to the obtained video stream address. It can be seen that a certain set video download process is completed through the chained requests A, B, and C.
[0042] Furthermore, in the embodiments of the present invention, construct interface objects (API objects) for each request; wherein, the interface object may include the following multiple components:
[0043] Request: Represents the network resource address of the request indicated by the API object, which includes a port number, a host name, request parameters, a request body, etc. It can be an HttpClient object or a Python Request object, and can also be other objects with HTTP request capabilities.
[0044] Callback: A function used to perform operations after a Request is sent and response data is obtained, such as data extraction, cleaning, and analysis, and can return an operation result.
[0045] NextApiList: Represents an array of API objects, indicating a list of multiple subsequent API objects of the current API object, that is, an array of adjacent subsequent request objects.
[0046] NextApi: Represents an API object, indicating the adjacent subsequent request object of the current API object.
[0047] PrevResult: Represents a response data object, indicating the response data result generated by the Callback function of the previous request.
[0048] Send (i.e., the request sending function): A function representing the action of sending a request.
[0049] Then (i.e., the associated request function): A function used to determine the call order dependency relationship of the request sending functions for each request.
[0050] That is, the interface object includes an associated request function and a request sending function; it also includes an adjacent subsequent request object or an array of adjacent subsequent request objects.
[0051] Step S102: Obtain the call order between any two adjacent requests among multiple requests, set the interface object of the subsequent request in the two adjacent requests as the input parameter of the associated request function of the previous request; determine the call order dependency relationship of the request sending functions for each request according to the input parameters of the associated request functions of each request.
[0052] Step S103: Based on the call order dependency relationship, call the request sending functions for each request to send requests, and determine the response data for multiple requests.
[0053] In an embodiment of the present invention, after receiving multiple requests, obtain the call order between the multiple requests (i.e., the multiple received requests indicate the call order between different requests), for example: three requests A, B, and C, and their call order is request A -> request B -> request C.
[0054] Furthermore, use the associated request function included in the interface object to determine the call order dependency relationship of the request sending functions.
[0055] Specifically, for example, for requests A -> B -> C with a call order dependency, obtain the call order between any two adjacent requests among the multiple requests. For example: A -> B are two adjacent requests with a call order, and B -> C are two adjacent requests with a call order.
[0056] Further, set the interface object of the subsequent request among the two adjacent requests as the input parameter of the associated request function of the previous request; based on the input parameters of the associated request functions of each request, determine the call order dependency of the send request functions of each request. For example: the associated request function is expressed as then(self, param); where param is the input parameter of the associated request function.
[0057] Figure 2A Shows a chain-like call order dependency determined through an associated request function among requests A -> B -> C. Based on the call order dependency, call the Send function (send request function) of request A to obtain the response data of request A. Request B sends request B and obtains the response data of request B based on the received response data of request A. Request C sends request C based on the received response data of request B and obtains the response data of request C as the final response data result for the multiple requests. As Figure 2A shown, the input parameter (NextApi) of the associated request function corresponding to request A is set as the interface object of request A, thereby determining the call order dependency between request A and request B; similarly, the call order dependency between request B and request C is determined. In Figure 2A the example shown, request B is the adjacent subsequent request of request A, and request C is the adjacent subsequent request of request B.
[0058] In an embodiment of the present invention, for a certain request, there may be multiple parallel adjacent subsequent requests. Then, an adjacent subsequent request object array is used to store the adjacent subsequent request objects of multiple adjacent subsequent requests. For example: Request A -> Requests [B, C] -> Request D; where Requests [B, C] are multiple parallel adjacent subsequent requests of Request A, and at the same time, Requests [B, C] are multiple parallel adjacent previous requests of Request D; for the scenario of multiple parallel adjacent subsequent requests, for example: Video website v divides the video stream into two independent interfaces, video (mp4) and audio (mp3). To download video data, these two parts need to be downloaded separately and then the audio is encoded into the video file. Then, Request A can be used to parse the video and audio addresses of the video page, Request B can be used to download the video (mp4 file) after obtaining the response data result of Request A, Request C can be used to download the audio (mp3 file) after obtaining the response data of Request A, and Request D can be used to obtain the final video data with the mp3 file encoded into the mp4. That is, for any current request, the interface object further includes: one or more of an adjacent subsequent request object and an adjacent subsequent request object array; setting the interface object of the subsequent request in two adjacent requests as the input parameter of the associated request function of the previous request includes: in the case where there is one adjacent subsequent request for the current request, setting the adjacent subsequent request object corresponding to the adjacent subsequent request as the input parameter of the associated request function of the current request; in the case where there are multiple parallel adjacent subsequent requests for the current request, using the adjacent subsequent request object array to store the adjacent subsequent request objects of multiple adjacent subsequent requests, and setting the adjacent subsequent request object array as the input parameter of the associated request function of the current request.
[0059] For Request A, the interface object of Request B is the adjacent subsequent request object of Request A; then, the adjacent subsequent request object B corresponding to the adjacent subsequent request (for example, represented by NextApi) is set as the input parameter of the associated request function of the current request. Or, for Request A, associated with an adjacent subsequent request object array (represented by NextApiList) including Request B and Request C, then the adjacent subsequent request object array is set as the input parameter of the associated request function of the current request. It can be understood that the adjacent subsequent request object array contains each parallel adjacent subsequent request object.
[0060] Further, when the interface object sends a request using the send request function, it is necessary to determine the network resource address, request parameters, request body, and other data required for the request according to the Request data; further, the interface object uses the Callback function, PrevResult object, etc. to obtain and manage the response data corresponding to the request.
[0061] After determining the call sequence dependency relationship for multiple requests using the constructed interface object, the step of executing the send request function of the call request to send the request has one or more of the following situations:
[0062] 1) For the case where the current request has an adjacent previous request.
[0063] For any current request, according to the call sequence dependency relationship, when it is determined that the current request has an adjacent previous request, obtain the previous response data of the adjacent previous request; determine the associated parameters of the current request according to the previous response data, so as to call the send request function of the current request based on the associated parameters.
[0064] Specifically, still taking the requests A -> request B -> request C with a call sequence dependency relationship as an example, for request B, it has an adjacent previous request (request A); for request C, it has an adjacent previous request (request B).
[0065] Since requests A -> request B -> request C have a call sequence dependency relationship, it means that request B depends on the response data of request A when sending the request, and request C depends on the response data of request B when sending the request (it can also be combined with the response data of request A according to the actual business scenario). For request B (i.e., the current request), it is necessary to determine the network resource address (URL) and / or request parameters of request B according to the response data obtained from request A. The network resource address and / or request parameters are the associated parameters. For example, for the video download scenario, the network resource address of request A is the homepage of the creator xyz. Parse the play volume ranking from the response data obtained from request A, and determine the first video in the video list as the video to be downloaded. Then, use the page address of the video to be downloaded as the associated parameter of request B, so that request B sends the request or obtains the video stream address of the video file through this associated parameter. That is, when it is determined that the current request has an adjacent previous request, obtain the previous response data of the adjacent previous request; determine the associated parameters of the current request according to the previous response data, so as to call the send request function of the current request based on the associated parameters.
[0066] Further, determine the associated parameters of the request based on the prior response data, and call the send request function of the request based on the associated parameters, including: in the case where it is determined that the current request has multiple parallel adjacent prior requests, obtain the prior response data of each adjacent prior request; combine the prior response data of each to determine the associated parameters of the current request, so as to call the send request function of the current request based on the associated parameters. For example, for request D, it is necessary to determine the associated parameters (URL and / or request parameters) used for sending the request based on the response data obtained from request B and request C. Therefore, the response data of multiple parallel adjacent prior requests can be processed through the PrevResult object (i.e., the response data object included in the interface object); it can be understood that the business code for parsing the specific associated data is written according to the actual business scenario, and the present invention does not limit the specific scenario and the specific content of the associated parameters.
[0067] 2) For the case where the current request has an adjacent subsequent request.
[0068] For any current request, according to the call order dependency relationship, in the case where it is determined that the current request has an adjacent subsequent request; obtain the self-response data of the current request; determine the associated parameters of the adjacent subsequent request according to the self-response data, so as to call the send request function of the adjacent subsequent request based on the associated parameters.
[0069] Specifically, still taking the requests A -> request B -> request C with a call order dependency relationship as an example, for request A (i.e., the current request), it has an adjacent subsequent request (request B).
[0070] Since requests A -> request B -> request C have a call order dependency relationship, it means that request B depends on the response data of request A when sending the request. That is, for request B (i.e., the adjacent subsequent request), it is necessary to determine the network resource address (URL) and / or request parameters of request C according to the self-response data obtained from request B, and the network resource address (URL) and / or request parameters are the associated parameters.
[0071] Further, for the current request, its self-response data can be obtained through the Callback function included in the interface object, and further determine the associated parameters of the adjacent subsequent request according to the self-response data.
[0072] Further, in the case where it is determined that the request has multiple parallel adjacent subsequent requests; determine the associated parameters of each adjacent subsequent request according to the self-response data. Specifically, the specific associated parameters (URL and / or request parameters) determined from the self-response data are set according to the actual business, and the present invention does not limit the specific associated parameters.
[0073] 3) For the case where there are adjacent previous requests and adjacent subsequent requests for the current request.
[0074] For any current request, based on the call sequence dependency relationship, when it is determined that the current request has adjacent previous requests and adjacent subsequent requests; obtain the previous response data of the adjacent previous request and the own response data of the current request; determine the associated parameters of the adjacent subsequent request by combining the previous response data and the own response data, and call the send request function of the adjacent subsequent request based on the associated parameters.
[0075] Specifically, still taking the requests A -> request B -> request C with a call sequence dependency relationship as an example, for request B (i.e., the current request), it has an adjacent previous request (request A) and an adjacent subsequent request (request C).
[0076] Since requests A -> request B -> request C have a call sequence dependency relationship, it means that request B (i.e., the current request) depends on the response data of request A when sending a request, and request C may also depend on the response data of request A (i.e., the previous response data of the adjacent previous request) and the response data of request B (the own response data of the current request) when sending a request. Determine the associated parameters of the adjacent subsequent request by combining the previous response data and the own response data, and call the send request function of the adjacent subsequent request based on the associated parameters.
[0077] By using the interface object to associate the input parameters of the request function to determine the call sequence dependency relationship of the send request functions of each request, and determining the associated data of the send request function based on the response data of adjacent requests to implement the operation of sending requests, so as to automatically execute the request sending according to its call sequence dependency relationship for requests with a call sequence, and determine the final response data (return result) of multiple requests, improving the flexibility, generality, and automation degree of processing multiple requests.
[0078] Further preferably, in the embodiments of the present invention, when sending requests by invoking the send request functions corresponding to each request, it includes: in response to sending requests in a concurrent manner, using multi-threading to concurrently execute the step of sending requests by invoking the send request functions corresponding to each request based on the call order dependency relationship. Specifically, a SendParallel function for the sending method of concurrent requests included in the interface object can be constructed to use this function to support multi-threaded concurrent request sending. Among them, during the process of using multi-threading to concurrently execute the step of sending requests by invoking the send request functions corresponding to each request based on the call order dependency relationship, monitor the number of sent requests. When it is detected that the number reaches the maximum number of sent requests, correspondingly handle the number of concurrent sent requests. It can be understood that what is executed concurrently is the entire request chain process of sending each request based on the call order dependency relationship; by the method of multi-threaded concurrent request sending, the efficiency of obtaining response data for multiple requests with call order dependency relationship is improved.
[0079] As Figure 2B shown, the embodiments of the present invention provide a schematic flow diagram for determining the call order dependency relationship of multiple requests; this flow may include the following steps:
[0080] Step S201: Obtain the input parameter information of the associated request function included in the interface object.
[0081] Specifically, in the embodiments of the present invention, the associated request function is expressed as then(self, param) for example; where self represents the interface object itself, and param is the input parameter of the associated request function.
[0082] Step S202: Determine whether the input parameter is the adjacent subsequent request object (expressed as NextApi for example). If so, execute Step S203; otherwise, execute Step S204.
[0083] Step S203: Execute the step of obtaining the input parameter of the associated request function included in the interface object of the adjacent subsequent request object, and end the current process.
[0084] Step S204: Determine whether the input parameter is an array of adjacent subsequent request objects (expressed as NextApiList for example). If so, execute Step S205; otherwise, execute Step S206.
[0085] Step S205: Set the array of adjacent subsequent request objects as the input parameter of the associated request function of the current request, and end the current process.
[0086] Step S206: Set the adjacent subsequent request object corresponding to the adjacent subsequent request as the input parameter of the associated request function of the current request, and end the current process.
[0087] Specifically, step S201 to step S206 describe that after constructing an interface object for each request, by obtaining the calling order between any two adjacent requests in multiple requests, the interface object of the later request in the two adjacent requests is set as the input parameter of the associated request function of the earlier request; thereby determining the process of the calling order dependency of the sending request function of each request.
[0088] It can be understood that after the interface object is constructed, the input parameter (param) of the associated request function contained therein has an initial default value, which is not the adjacent subsequent request object (for example, represented as NextAPI). Through steps S201 to S206, the interface object of the adjacent subsequent request is set as the input parameter of the associated request function of the current request, and the call sequence dependency relationship based on which the request is called and sent before each request is established. That is, for any current request, the interface object also includes: one or more of the adjacent subsequent request object and the adjacent subsequent request object array; the interface object of the subsequent request in the two adjacent requests is set as the input parameter of the associated request function of the previous request, including: for the case where there is one adjacent subsequent request in the current request, the adjacent subsequent request object corresponding to the adjacent subsequent request is set as the input parameter of the associated request function of the current request; for the case where there are multiple adjacent subsequent requests in parallel in the current request, the adjacent subsequent request object array is used to store the adjacent subsequent request objects of multiple adjacent subsequent requests, and the adjacent subsequent request object array is set as the input parameter of the associated request function of the current request.
[0089] Through steps S201 to S206, the interface object of the adjacent subsequent request is set as the input parameter of the associated request function of the current request, and a call order dependency relationship based on which each request is called and sent is established before each request, thereby automatically determining the call order dependency relationship for each request. The embodiment of the present invention does not limit the specific number of multiple requests. When the number of requests is large, the efficiency of determining the call order dependency relationship of multiple requests is improved; in business scenarios where the order of requests needs to be changed or the frequency of changing the number of requests is high, the embodiment of the present invention further improves the flexibility and versatility of determining the call order dependency relationship of multiple requests.
[0090] like Figure 3 As shown, an embodiment of the present invention provides a process for processing a request, which may include the following steps:
[0091] Step S301: Based on the calling sequence dependency, call the sending request function of each request to send the request and obtain the response data of the current request.
[0092] Step S302: Determine whether the input parameter of the associated request function is an array of adjacent subsequent request objects. If so, execute step S303; otherwise, execute step S304.
[0093] Step S303: Determine the associated parameters of each adjacent subsequent request according to its own response data, and end the current process.
[0094] Step S304: Determine whether the input parameter of the associated request function is an adjacent subsequent request object. If so, execute step S305; otherwise, end the current process.
[0095] Step S305: determining the associated parameters of the adjacent subsequent request according to its own response data; calling the sending request function of the adjacent subsequent request based on the associated parameters, and ending the current process.
[0096] The description of step S301 to step S305 is to call the sending request function of each request to send the request based on the calling order dependency, including: for any current request, according to the calling order dependency, when it is determined that the current request has an adjacent subsequent request; obtaining the current request's own response data; determining the associated parameters of the adjacent subsequent request based on the own response data, and calling the sending request function of the adjacent subsequent request based on the associated parameters.
[0097] When it is determined that the request has multiple parallel adjacent subsequent requests; the associated parameters of each adjacent subsequent request are determined according to the own response data.
[0098] The adjacent subsequent request object is judged by the input parameters of the associated request function of the interface object, and the associated parameters are determined for the sending request function of the adjacent subsequent request object based on the response data, thereby achieving the effect of automatically driving and sending the call request according to the calling order dependency, and improving the reliability, flexibility and automation of sending requests and processing response data according to the calling order dependency.
[0099] like Figure 4 As shown, an embodiment of the present invention provides a device 400 for processing a request, comprising: a request receiving module 401, an association determining module 402 and a request sending module 403; wherein,
[0100] The request receiving module 401 is used to receive multiple requests and construct an interface object for each request; wherein the interface object includes an association request function and a send request function;
[0101] The association determination module 402 is used to obtain the calling order between any two adjacent requests in the multiple requests, set the interface object of the later request in the two adjacent requests as the input parameter of the association request function of the earlier request, and determine the calling order dependency of the sending request function of each request according to the input parameter of the association request function of each request;
[0102] The request sending module 403 is configured to call the request sending functions of each request based on the call sequence dependency relationship to send requests, and determine the response data of multiple requests.
[0103] An embodiment of the present invention further provides an electronic device for processing requests, including: one or more processors; a storage device for storing one or more programs, which when executed by the one or more processors cause the one or more processors to implement the method provided in any of the above embodiments.
[0104] An embodiment of the present invention further provides a computer-readable medium having a computer program stored thereon, and when the program is executed by a processor, the method provided in any of the above embodiments is implemented.
[0105] An embodiment of the present invention further provides a computer program product, including a computer program, and when the computer program is executed by a processor, any of the methods in the above method for processing requests is implemented.
[0106] Figure 5 An exemplary system architecture 500 to which the method for processing requests or the apparatus for processing requests according to the embodiments of the present invention can be applied is shown.
[0107] As Figure 5 shown, the system architecture 500 may include terminal devices 501, 502, 503, a network 504, and a server 505. The network 504 is used to provide a medium for a communication link between the terminal devices 501, 502, 503 and the server 505. The network 504 may include various connection types, such as wired, wireless communication links, or fiber optic cables, etc.
[0108] Users can use the terminal devices 501, 502, 503 to interact with the server 505 through the network 504 to receive or send messages, etc. Various client applications may be installed on the terminal devices 501, 502, 503, such as an e-commerce client application, a web browser application, a search application, an instant messaging tool, etc.
[0109] The terminal devices 501, 502, 503 may be various electronic devices having a display screen and supporting various client applications, including but not limited to smart phones, tablet computers, laptop portable computers, and desktop computers, etc.
[0110] The server 505 may be a server providing various services, such as a background management server that provides support for the client applications used by users using the terminal devices 501, 502, 503. The background management server may process multiple received requests and feed back the final response data of the multiple requests obtained to the terminal devices.
[0111] It should be noted that the method for processing requests provided in the embodiments of the present invention is generally executed by the server 505. Correspondingly, the device for processing requests is generally provided in the server 505.
[0112] It should be understood that Figure 5 the number of terminal devices, networks, and servers in
[0113] is merely illustrative. According to actual requirements, there can be any number of terminal devices, networks, and servers. Figure 6 is merely illustrative. According to actual requirements, there can be any number of terminal devices, networks, and servers. Figure 6 The terminal device shown is merely an example and should not impose any limitations on the functions and usage scope of the embodiments of the present invention.
[0114] As Figure 6 shown, the computer system 600 includes a central processing unit (CPU) 601, which can execute various appropriate actions and processes according to the program stored in the read-only memory (ROM) 602 or the program loaded from the storage section 608 into the random access memory (RAM) 603. In the RAM 603, various programs and data required for the operation of the system 600 are also stored. The CPU 601, ROM 602, and RAM 603 are connected to each other via a bus 604. The input / output (I / O) interface 605 is also connected to the bus 604.
[0115] The following components are connected to the I / O interface 605: an input section 606 including a keyboard, a mouse, etc.; an output section 607 including, for example, a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker; a storage section 608 including a hard disk, etc.; and a communication section 609 including a network interface card such as a LAN card, a modem, etc. The communication section 609 performs communication processing via a network such as the Internet. A drive 610 is also connected to the I / O interface 605 as required. A removable medium 611, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 610 as required, so that the computer program read from it can be installed into the storage section 608 as required.
[0116] In particular, according to the embodiments disclosed in the present invention, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, the embodiments disclosed in the present invention include a computer program product that includes a computer program carried on a computer-readable medium, and the computer program contains program codes for executing the methods shown in the flowcharts. In such an embodiment, the computer program can be downloaded and installed from the network through the communication section 609, and / or installed from the removable medium 611. When the computer program is executed by the central processing unit (CPU) 601, the above-described functions defined in the system of the present invention are executed.
[0117] It should be noted that the computer-readable medium shown in the present invention can be a computer-readable signal medium or a computer-readable storage medium or any combination of the two. The computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the above. More specific examples of the computer-readable storage medium can include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present invention, the computer-readable storage medium can be any tangible medium that contains or stores a program, and the program can be used by or in combination with an instruction execution system, apparatus, or device. In the present invention, the computer-readable signal medium can include a data signal propagated in a baseband or as part of a carrier wave, which carries the computer-readable program code. Such a propagated data signal can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. The computer-readable signal medium can also be any computer-readable medium other than the computer-readable storage medium, and the computer-readable medium can send, propagate, or transmit a program for use by or in combination with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted by any appropriate medium, including but not limited to: wireless, wire, optical fiber, RF, etc., or any suitable combination of the above.
[0118] The flowcharts and block diagrams in the accompanying drawings illustrate the possible architectures, functions, and operations of systems, methods, and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagram may represent a module, a segment of a program, or a portion of code that contains one or more executable instructions for implementing the specified logical function. It should also be noted that, in some alternative implementations, the functions noted in the blocks may occur in a different order than that noted in the accompanying drawings. For example, two consecutive blocks shown may actually be executed substantially in parallel, or they may sometimes be executed in the reverse order, depending on the functions involved. It should also be noted that each block in the block diagram or flowchart, as well as combinations of blocks in the block diagram or flowchart, may be implemented by a dedicated hardware-based system that performs the specified functions or operations, or may be implemented by a combination of dedicated hardware and computer instructions.
[0119] The modules and / or units involved in the embodiments of the present invention can be implemented in software or in hardware. The described modules and / or units can also be provided in a processor. For example, it can be described as: a processor includes a request receiving module, an association determining module, and a request sending module. Among them, the names of these modules do not, in some cases, limit the module itself. For example, the request receiving module can also be described as "a module that receives multiple requests and constructs interface objects for each request".
[0120] As another aspect, the present invention also provides a computer-readable medium, which can be included in the device described in the above embodiments; or it can exist separately and not be assembled into the device. The above computer-readable medium carries one or more programs. When the one or more programs are executed by a device, the device includes: being able to construct interface objects for multiple requests, determining the call order dependency relationship of the send request functions of each request by using the input parameters of the association request functions included in the set interface objects, and based on the call order dependency relationship, calling the send request functions of each request to send requests, so as to determine the response data of multiple requests; the embodiments of the present invention improve the flexibility and generality of processing multiple requests, and improve the efficiency and automation degree of processing requests.
[0121] The above specific embodiments do not limit the protection scope of the present invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions may occur depending on design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention shall be included within the protection scope of the present invention.
Claims
1. A method for processing requests, characterized in that, include: Receiving multiple requests and constructing an interface object for each of the requests; wherein the interface object includes an association request function and a send request function; Obtaining a calling order between any two adjacent requests among the multiple requests, and setting the interface object of the later request among the two adjacent requests as an input parameter of the associated request function of the earlier request; Determine the calling sequence dependency of the sending request function of each request according to the input parameters of the associated request function of each request; Based on the calling sequence dependency, the sending request function of each request is called to send the request, and the response data of the multiple requests is determined.
2. The method according to claim 1, characterized in that Call the corresponding request sending function of each request to send the request, including: In response to sending the requests in a concurrent manner, the step of sending the requests by calling the sending request functions corresponding to the various requests based on the calling sequence dependency is performed concurrently by multiple threads.
3. The method according to claim 1, characterized in that For any current request, the interface object further includes: an adjacent subsequent request object, an array of adjacent subsequent request objects or one or more thereof; The step of setting the interface object of the later request of the two adjacent requests as an input parameter of the associated request function of the earlier request includes: In case that there is an adjacent subsequent request for the current request, setting the adjacent subsequent request object corresponding to the adjacent subsequent request as an input parameter of the associated request function of the current request; In case that there are multiple parallel adjacent subsequent requests for the current request, the adjacent subsequent request object array is used to store the adjacent subsequent request objects of the multiple adjacent subsequent requests, and the adjacent subsequent request object array is set as the input parameter of the associated request function of the current request.
4. The method according to claim 1, characterized in that The step of calling a request sending function of each request to send a request based on the calling sequence dependency relationship includes: For any current request, According to the calling sequence dependency, when it is determined that the current request has an adjacent previous request, obtaining the previous response data of the adjacent previous request; The associated parameters of the current request are determined according to the previous response data, so as to call a send request function of the current request based on the associated parameters.
5. The method according to claim 4, characterized in that The determining the associated parameters of the request according to the prior response data, and calling the sending request function of the request based on the associated parameters, comprises: When it is determined that the current request has multiple parallel adjacent previous requests, obtaining the previous response data of each of the adjacent previous requests; In combination with each of the previous response data, the associated parameters of the current request are determined, so as to call the send request function of the current request based on the associated parameters.
6. The method according to claim 1, characterized in that The step of calling a request sending function of each request to send a request based on the calling sequence dependency relationship includes: For any current request, According to the calling sequence dependency, when it is determined that the current request has an adjacent subsequent request; Obtaining the current request's own response data; The associated parameters of the adjacent subsequent request are determined according to the own response data, so as to call a sending request function of the adjacent subsequent request based on the associated parameters.
7. The method according to claim 6, characterized in that The determining, according to the own response data, the associated parameter of the adjacent subsequent request comprises: In the case where it is determined that the request has a plurality of parallel adjacent subsequent requests; The associated parameters of each of the adjacent subsequent requests are determined according to the own response data.
8. The method according to claim 1, characterized in that The step of calling a request sending function of each request to send a request based on the calling sequence dependency relationship includes: For any current request, According to the calling sequence dependency, when it is determined that the current request has an adjacent preceding request and an adjacent subsequent request; Obtaining the previous response data of the adjacent previous request and the own response data of the current request; The associated parameters of the adjacent subsequent request are determined in combination with the previous response data and the own response data, and the sending request function of the adjacent subsequent request is called based on the associated parameters.
9. An apparatus for processing requests, characterized in that, include: A receiving request module, a determining association module and a sending request module; wherein, The request receiving module is used to receive multiple requests and construct an interface object for each of the requests; wherein the interface object includes an association request function and a send request function; The association determination module is used to obtain the calling order between any two adjacent requests among the multiple requests, set the interface object of the later request among the two adjacent requests as the input parameter of the association request function of the earlier request, and determine the calling order dependency relationship of the sending request function of each request according to the input parameter of the association request function of each request; The sending request module is used to call the sending request function of each request to send the request based on the calling sequence dependency, and determine the response data of the multiple requests.
10. An electronic device, characterized in that, include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 8.
11. A computer-readable medium having a computer program stored thereon, characterized in that, When the program is executed by a processor, the method according to any one of claims 1 to 8 is implemented.
12. A computer program product, comprising a computer program, characterized in that, When the program is executed by a processor, the method according to any one of claims 1 to 8 is implemented.