Api aggregation method and apparatus, electronic device, and storage medium
By acquiring user requests and using aggregation configuration files to determine the target API aggregation method, the problem of untimely response and low development efficiency caused by calling a large number of API requests in complex business logic is solved, and a more efficient API call and development process is achieved.
Patent Information
- Application Number
- CN202210621135.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-01
- Publication Date
- 2026-03-03
- Estimated Expiration
- 2042-06-01
AI Technical Summary
In complex business logic, making a large number of API requests leads to untimely responses and low testing and development efficiency.
By obtaining user requests and using the aggregation configuration file to determine the target API aggregation method, the API corresponding to the target API aggregation method is called to respond to the user requests. The aggregation configuration file can be modified according to user needs.
It improved response speed and increased testing and development efficiency.
Smart Images

Figure CN114995791B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data processing technology, and more specifically, to an API aggregation method, apparatus, electronic device, and storage medium. Background Technology
[0002] An Application Programming Interface (API) is a set of conventions that govern the interaction between different components of a software system. The primary purpose of an API is to provide applications and developers with the ability to access a set of routines without needing access to the source code or understanding the details of the internal workings. The software that provides the functionality defined by the API is called the implementation of that API.
[0003] Complex business logic requires a large number of API requests, resulting in untimely responses and low efficiency in testing and development. Summary of the Invention
[0004] In view of this, embodiments of this application propose an API aggregation method, apparatus, electronic device, and storage medium to improve the above-mentioned problems.
[0005] In a first aspect, embodiments of this application provide an API aggregation method, comprising: obtaining a user request; determining a target API aggregation method corresponding to the user request based on the user request and an aggregation configuration file, wherein the aggregation configuration file includes a correspondence between business scenarios and API aggregation methods; and calling an API corresponding to the target API aggregation method according to the target API aggregation method, and returning data corresponding to the user request.
[0006] Secondly, embodiments of this application provide an API aggregation device, comprising: an acquisition module, configured to acquire a user request; a target API aggregation method, configured to determine a target API aggregation method corresponding to the user request based on the user request and an aggregation configuration file, wherein the aggregation configuration file includes a correspondence between business scenarios and API aggregation methods; and an API invocation module, configured to invoke an API corresponding to the target API aggregation method based on the target API aggregation method, and return data corresponding to the user request.
[0007] Thirdly, embodiments of this application provide an electronic device, including: a processor; a memory, on which computer-readable instructions are stored, which, when executed by the processor, implement the API aggregation method described above.
[0008] Fourthly, embodiments of this application provide a computer-readable storage medium storing computer-readable instructions that, when executed by a processor, implement the API aggregation method described above.
[0009] In this application's solution, the target API aggregation method is first determined using the user request and the aggregation configuration file. Then, the API corresponding to the target API aggregation method is called to respond to the user request and return the data required by the user. This allows a user request that would normally require calling multiple APIs to be fulfilled to be fulfilled by calling only one or a few APIs aggregated using the target API aggregation method adapted to the user request, thus improving the response rate. Furthermore, the target API aggregation method is implemented through the aggregation configuration file, which can be modified according to the user's specific needs, improving the efficiency of aggregation testing and development. Attached Figure Description
[0010] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0011] Figure 1 A structural block diagram of an electronic device suitable for implementing embodiments of this application is shown.
[0012] Figure 2 A flowchart of an API aggregation method provided in an embodiment of this application is shown.
[0013] Figure 3 It shows Figure 2 A flowchart of one embodiment of step S220.
[0014] Figure 4 A flowchart of an API aggregation method according to another embodiment of this application is shown.
[0015] Figure 5 A flowchart illustrating the one-to-one dependency aggregation method of this application is shown.
[0016] Figure 6 A flowchart of an API aggregation method according to yet another embodiment of this application is shown.
[0017] Figure 7 A flowchart illustrating the many-to-many dependency aggregation method of this application is shown.
[0018] Figure 8 A flowchart of an API aggregation method according to another embodiment of this application is shown.
[0019] Figure 9 A flowchart illustrating the parallel input aggregation method of this application is shown.
[0020] Figure 10 A flowchart of an API aggregation method according to another embodiment of this application is shown.
[0021] Figure 11 A flowchart illustrating the parallel merging and aggregation method of this application is shown.
[0022] Figure 12 A flowchart illustrating configuration file monitoring in the API aggregation method provided in this application embodiment is shown.
[0023] Figure 13 An API gateway architecture diagram of an embodiment of this application is shown.
[0024] Figure 14 A timing diagram of an embodiment of this application is shown.
[0025] Figure 15 A block diagram of an API aggregation apparatus provided in an embodiment of this application is shown. Detailed Implementation
[0026] Exemplary embodiments will now be described more fully with reference to the accompanying drawings. However, these exemplary embodiments can be implemented in many forms and should not be construed as limited to the examples set forth herein; rather, these embodiments are provided to make this application more comprehensive and complete, and to fully convey the concept of the exemplary embodiments to those skilled in the art.
[0027] Furthermore, the described features, structures, or characteristics can be combined in any suitable manner in one or more embodiments. Numerous specific details are provided in the following description to give a thorough understanding of embodiments of this application. However, those skilled in the art will recognize that the technical solutions of this application can be practiced without one or more of the specific details, or other methods, components, apparatuses, steps, etc., can be employed. In other instances, well-known methods, apparatuses, implementations, or operations are not shown or described in detail to avoid obscuring various aspects of this application.
[0028] The block diagrams shown in the accompanying drawings are merely functional entities and do not necessarily correspond to physically independent entities. That is, these functional entities can be implemented in software, in one or more hardware modules or integrated circuits, or in different network and / or processor devices and / or microcontroller devices.
[0029] The flowcharts shown in the accompanying drawings are merely illustrative and do not necessarily include all content and operations / steps, nor do they necessarily have to be performed in the described order. For example, some operations / steps can be broken down, while others can be combined or partially combined; therefore, the actual execution order may change depending on the specific circumstances.
[0030] It should be noted that "multiple" in this article refers to two or more. "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A alone, A and B simultaneously, or B alone. The character " / " generally indicates that the preceding and following related objects have an "or" relationship.
[0031] For businesses with a large number of services, high complexity, and large scale, a gateway service is needed to uniformly manage backend service APIs and forward requests based on frontend requests. If the API request logic is complex, the frontend needs to be aware of the business logic and make a large number of API requests, resulting in significant network overhead between the frontend and backend, as well as high complexity in frontend development.
[0032] Therefore, the inventors have proposed an API aggregation method, apparatus, electronic device, and storage medium. First, the target API aggregation method is determined using the user request and an aggregation configuration file. Then, the API corresponding to the target API aggregation method is called to respond to the user request and return the data required by the user. This allows a user request that would normally require calling multiple APIs to be fulfilled to be fulfilled by calling only one or a few APIs aggregated through the target API aggregation method, thereby improving the response rate. Furthermore, the target API aggregation method is implemented through an aggregation configuration file, which can be modified according to specific user needs, improving the efficiency of aggregation testing and development.
[0033] Please see Figure 1 , Figure 1 A structural block diagram of an electronic device suitable for implementing embodiments of this application is shown. Figure 1 The electronic devices shown may include terminal devices or servers. Terminals may be smartphones, gateways, tablets, laptops, desktop computers, etc. Servers may be independent physical servers, server clusters or distributed systems composed of multiple physical servers, or cloud servers that provide basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms.
[0034] exist Figure 1In the illustrated electronic device, the memory 1005, serving as a storage medium, may include an operating system, a data storage module, a network communication module, a user interface module, and electronic programs. The network interface 1004 is primarily used for data communication with a network server; the user interface 1003 is primarily used for data interaction with a user; the communication bus 1002 is primarily used for communication and interaction between the memory 1005, network interface 1004, user interface 1003, and the server. The processor 1001 and memory 1005 in the electronic device of this invention can be disposed within the electronic device. The electronic device uses the processor 1001 to call the API aggregation device stored in the memory 1005 and executes the API aggregation method provided in the embodiments of this application.
[0035] Processor 1001 may include one or more processing cores. Processor 1001 connects to various parts of the electronic device using various interfaces and lines, and performs various functions and processes data by running or executing instructions, programs, code sets, or instruction sets stored in memory 1005, and by calling data stored in memory 1005. Optionally, processor 1001 may be implemented using at least one hardware form of Digital Signal Processing (DSP), Field-Programmable Gate Array (FPGA), or Programmable Logic Array (PLA). Processor 1001 may integrate one or a combination of several of the following: Central Processing Unit (CPU), Graphics Processing Unit (GPU), and Modem. The CPU primarily handles the operating system, user interface, and applications; the GPU is responsible for rendering and drawing the displayed content; and the modem handles wireless communication. It is understood that the modem may also not be integrated into processor 1001 and may be implemented separately using a communication chip.
[0036] The memory 1005 may include random access memory (RAM) or read-only memory (ROM). The memory 1005 can be used to store instructions, programs, code, code sets, or instruction sets. The memory 1005 may include a program storage area and a data storage area. The program storage area may store instructions for implementing an operating system, instructions for implementing at least one function (such as touch functionality, alarm functionality, etc.), instructions for implementing the various method embodiments described below, etc. The data storage area may also store data created during the use of the electronic device (such as spoofed response commands, acquired process states, etc.).
[0037] Those skilled in the art will understand that Figure 1 The structure shown does not constitute a limitation on the electronic device and may include more or fewer components than shown, or combine certain components, or have different component arrangements.
[0038] Figure 2 This is a flowchart illustrating an API aggregation method according to an embodiment of this application, which can be executed by an electronic device with processing capabilities (e.g., a gateway). See also... Figure 2 As shown, the method includes at least steps S210 to S230, which are described in detail below:
[0039] Step S210: Obtain the user request.
[0040] Get the user request sent by the front end. The user request may carry information indicating the business scenario, such as business code or scenario requirements.
[0041] Step S220: Based on the user request and the aggregation configuration file, determine the target API aggregation method corresponding to the user request. The aggregation configuration file includes the correspondence between business scenarios and API aggregation methods.
[0042] A user request corresponds to a business scenario. The business scenario can be one explicitly indicated in the user request or one inferred from the user request.
[0043] A configuration file is a computer file that configures different objects differently. Configuration files include local user configuration files, roaming user configuration files, forced user configuration files, and temporary configuration files.
[0044] In this embodiment, the aggregation configuration file refers to a file in which multiple specific API aggregation methods and their corresponding business scenarios are written using code. The aggregation configuration file includes the correspondence between business scenarios and API aggregation methods. Developers can set and update the aggregation configuration file based on experience data and specific business scenarios. It is understood that, to improve efficiency, target API aggregation methods can be configured for different business scenarios and specific needs.
[0045] When a user request matches a business scenario in the aggregation configuration file, the APIs that the user request needs to call are aggregated according to the API aggregation method corresponding to that business scenario. The aggregation configuration file can be a workflow configuration file, and the configuration file type is not specifically limited.
[0046] For example, the specific method for determining the target API aggregation method corresponding to the user request, based on the user request and the aggregation configuration file, may include... Figure 3 The process shown is as follows:
[0047] Step S222: Determine the business scenario corresponding to the user request based on the user request.
[0048] In some implementations, the user request may carry a business scenario code or identifier, and the corresponding business scenario can be determined based on the code or identifier.
[0049] In other implementations, business scenarios can be determined using a pre-trained model, which can be trained using a large number of user requests. Inputting the acquired user requests into the pre-trained model yields the corresponding business scenario.
[0050] Step S224: Based on the determined business scenario and the correspondence between the business scenario and the API aggregation method in the aggregation configuration file, obtain the target API aggregation method corresponding to the user request.
[0051] Since the aggregation configuration file contains the correspondence between business scenarios and API aggregation methods, once the business scenario corresponding to the user request is determined, the API aggregation method corresponding to that business scenario can be obtained from the aggregation configuration file and used as the target API aggregation method for the user request.
[0052] Step S230: According to the target API aggregation method, call the API corresponding to the target API aggregation method and return the data corresponding to the user request.
[0053] Each target API aggregation method may involve multiple APIs. When a target API aggregation method is called, these multiple APIs will be invoked to perform their functions. The aggregation method can be either a dependency aggregation method or a parallel aggregation method, thereby obtaining the data required by the user's request.
[0054] Dependency aggregation refers to a situation where multiple APIs required by a user request each have their own function, and the data processed by one or more APIs depends on the output of one or more previous APIs. Parallel aggregation refers to a situation where there is no dependency relationship between multiple APIs required by a user request.
[0055] For example, if a user requests "monthly bill for this year," the corresponding business scenario is "monthly bill." If each monthly bill corresponds to one API, then the 12 APIs can be aggregated using the aggregation method corresponding to the "monthly bill" business scenario, thereby returning a yearly monthly bill to the customer. This aggregation method is called parallel aggregation.
[0056] If the user request is "the first week's bill of the first month of this year", each monthly bill corresponds to one API, and each weekly bill in the month corresponds to one API. In this case, the "weekly bill" in the business context is aggregated using a dependency aggregation method. First, the API corresponding to the first month's bill is called from the current year's bill API, and then the API corresponding to the first week's bill is called from the first month's bill, thereby returning the customer's first week's bill data for the first month.
[0057] In this application, the target API aggregation method is first determined using the user request and the aggregation configuration file. Then, the API corresponding to the target API aggregation method is called to respond to the user request and return the data required by the user. This allows a user request that would normally require calling multiple APIs to be fulfilled to be fulfilled by calling only one or a few APIs aggregated through the target API aggregation method, thereby improving the response rate. Moreover, the target API aggregation method is implemented through the aggregation configuration file, which can be modified according to the user's specific needs, improving the efficiency of aggregation testing and development.
[0058] Figure 4 A flowchart of an API aggregation method according to another embodiment of this application is shown. This method can be executed by an electronic device with processing capabilities, and is not specifically limited herein. (Refer to...) Figure 4 As shown, the method includes:
[0059] Step S310: Obtain the user request.
[0060] Step S320: Based on the user request and the aggregation configuration file, determine the target API aggregation method corresponding to the user request. The aggregation configuration file includes the correspondence between business scenarios and API aggregation methods.
[0061] The specific implementation of steps S310 to S320 can be referred to the corresponding steps S210 to S220 in the aforementioned embodiments, and will not be repeated here.
[0062] Step S330: When the target API aggregation method is determined to be a one-to-one dependency aggregation method, multiple APIs are called sequentially according to the target API aggregation method, with the output of the previous API serving as the input of the next API.
[0063] The input of one API is used as the output of the next API. The user request is processed layer by layer to obtain the final API output result, thereby obtaining the data corresponding to the user request.
[0064] For example, in a speech recommendation scenario, API1 uploads the corpus, API2 preprocesses the corpus, and API3 performs speech mining. First, the corpus is uploaded, then the uploaded corpus is processed, and finally, data mining is performed on the processed corpus to obtain the speech recommendation data mined by API3 that the user needs.
[0065] Step S340: Return the data output by the last API as the data corresponding to the user request.
[0066] In this embodiment, multiple APIs are called sequentially, with the output of one API serving as the input of the next API. This aggregation method is a one-to-one dependency aggregation method. (See also...) Figure 5 , Figure 5 The flowchart of the one-to-one dependency aggregation method in this application is shown. The aggregation configuration file corresponding to the one-to-one dependency aggregation method can be implemented through the following:
[0067]
[0068] In this context, `call API1{input:in=firstInput}` means that API1 is the input of the file `firstInput`, `call API2{input:in=API1.out}` means that the input of API2 is obtained from the output of API1, and so on. Therefore, `callAPI3{input:in=API2.out}` means that the input of API3 is the output of API2, and the data returned to the user is the output of API3.
[0069] Figure 6A flowchart of another embodiment of the API aggregation method of this application is shown. This method can be executed by an electronic device with processing capabilities, and is not specifically limited herein. (Refer to...) Figure 6 As shown, the method includes:
[0070] Step S410: Obtain the user request.
[0071] Step S420: Based on the user request and the aggregation configuration file, determine the target API aggregation method corresponding to the user request. The aggregation configuration file includes the correspondence between business scenarios and API aggregation methods.
[0072] The specific implementation of steps S410 to S420 can be referred to the corresponding steps S210 to S220 in the aforementioned embodiments, and will not be repeated here.
[0073] Step S430: When the target API aggregation method is determined to be many-to-many dependency aggregation in the dependency aggregation method, according to the target API aggregation method, the first API, multiple second APIs and the third API are called in sequence, and the output of the first API is used as the input of multiple second APIs, and the output of the multiple second APIs is used as the input of the third API.
[0074] For a user request, the necessary API, API1, is parsed out. API1 decomposes the user request into different request requirements. Different APIs are needed to process different request requirements. Therefore, the output of API1 is used as the input of multiple different APIs. After processing by multiple APIs, some of the processed data is permanently saved, while the data from other APIs is used as the input of the next API. The user request is then further parsed until the data corresponding to the user request is obtained.
[0075] For example, in a labeling scenario, after the API1 preprocessing process is completed, API2 pre-labeling, API3 deactivated data processing, and API4 clustering are performed simultaneously, and there is no dependency between the multiple processes. Among them, the API3 deactivated data is no longer output after processing, and the final API4 labeling model result is the processing of the output of API2 pre-labeling and API3 deactivated data processing.
[0076] Step S440: Return the data output by the last API as the data corresponding to the user request.
[0077] In this embodiment, the API aggregation method that sequentially calls a first API, multiple second APIs, and a third API, using the output of the first API as the input of each of the multiple second APIs, is a many-to-many dependency aggregation method. (See also...) Figure 7 , Figure 7The flowchart of the many-to-many dependency aggregation method of this application is shown. The aggregation configuration file for the many-to-many dependency aggregation method can be the following code:
[0078]
[0079] In this context, `call API1{input:in=firstInput}` means that API1 is used as the input to the file `firstInput`. `call API2{input:in=API1.out}`, `call API3{input:in=API1.out}`, `call API4{input:in=API1.out}`, and `call API5{input:in=API1.out}` mean that the inputs of API2, API3, API4, and API5 are obtained from the output of API1. `call API6{input:in1=API2.out,in2=API4.out}` means that the input of API6 is the output of API2 and API4. Finally, the data returned to the user is the output of API3. The data output by API3 and API5 will be stored or used as the input of other APIs, which is not limited here.
[0080] Figure 8 A flowchart of an API aggregation method according to a fourth embodiment of this application is shown. This method can be executed by an electronic device with processing capabilities, and is not specifically limited herein. (Refer to...) Figure 8 As shown, the method includes:
[0081] Step S510: Obtain the user request.
[0082] Step S520: Based on the user request and the aggregation configuration file, determine the target API aggregation method corresponding to the user request. The aggregation configuration file includes the correspondence between business scenarios and API aggregation methods.
[0083] The specific implementation of steps S510 to S5420 can be referred to the corresponding steps S210 to S220 in the aforementioned embodiments, and will not be repeated here.
[0084] Step S530: When the target API aggregation method is determined to be parallel input aggregation in the parallel aggregation method, multiple first APIs and second APIs are called sequentially according to the target API aggregation method, and the outputs of the multiple first APIs are used as the inputs of the second APIs.
[0085] The user request is parsed to determine that multiple different APIs are needed to process it. The outputs of the first APIs are then used as the inputs of the second APIs, and the outputs of the second APIs are returned as the data corresponding to the user request.
[0086] For example, in e-commerce copywriting generation, API1 generates selling points, API2 categorizes selling points, and there is no dependency between the two APIs. API3 generates copy, which requires the output of API1 and API2 to execute. Therefore, it can be executed through parallel aggregation.
[0087] Step S540: Return the data output by the last API as the data corresponding to the user request.
[0088] In this embodiment, the API aggregation method that sequentially calls multiple first APIs and second APIs, and uses the outputs of the multiple first APIs as the inputs of the second APIs, is a parallel input aggregation method. (See also...) Figure 9 , Figure 9 The flowchart illustrating the parallel input aggregation method of this application is shown. The aggregation configuration file for the parallel input aggregation method can be the following code:
[0089]
[0090] Here, scatter(param in firstInput) means obtaining multiple parallel and independent APIs through the scatter keyword of the scatter aggregation function, and then using the gather keyword to aggregate the outputs of the multiple parallel and independent APIs. The output of the scatter aggregation function is used as the input of API4, and the final output is the output of API4.
[0091] Figure 10 A flowchart of the API aggregation method according to the fifth embodiment of this application is shown. This method can be executed by an electronic device with processing capabilities, and is not specifically limited herein. (Refer to...) Figure 10 As shown, the method includes:
[0092] Step S610: Obtain the user request.
[0093] Step S620: Based on the user request and the aggregation configuration file, determine the target API aggregation method corresponding to the user request. The aggregation configuration file includes the correspondence between business scenarios and API aggregation methods.
[0094] The specific implementation of steps S610 to S620 can be referred to the corresponding steps S210 to S220 in the aforementioned embodiments, and will not be repeated here.
[0095] Step S630: When the target API aggregation method is determined to be parallel merge aggregation in parallel aggregation method, multiple first APIs are called sequentially according to the target API aggregation method, and the outputs of the multiple first APIs are output at the same time.
[0096] The system retrieves multiple APIs required by the user's request. These APIs process the data and output it simultaneously to obtain the data corresponding to the user's request.
[0097] For example, in a similarity question mining scenario, API1 retrieves the clustering results of similar questions, and API2 retrieves the recommendation results of similar questions. Then, by using the API parallel aggregation method, these two APIs can be aggregated to return the clustering and recommendation results of similar questions.
[0098] Step S640: Return the output of the plurality of first APIs as the data corresponding to the user request.
[0099] In this embodiment, the API aggregation method that sequentially calls multiple first APIs and simultaneously outputs the outputs of these multiple first APIs can be a parallel merging aggregation method. (Refer to...) Figure 11 , Figure 11 The flowchart of the parallel merging aggregation method of this application is shown. The aggregation configuration file for the parallel merging aggregation method can be the following code:
[0100]
[0101] In this context, `call API1{input:in=firstInput}`, `call API2{input:in=firstInput}`, and `call API3{input:in=firstInput}` represent that the inputs of API1, API2, and API3 come from the same file. The `merge` function is used to merge the outputs of API1, API2, and API3, and the merged result is then output.
[0102] Reference Figure 12 In this application, the method may include:
[0103] Step S710: Read and parse the aggregation configuration file.
[0104] Step S720: When the update information of the aggregation configuration file is obtained, the correspondence between the business scenario and the API aggregation method is updated according to the update information.
[0105] The monitoring tool reads and parses the aggregation configuration file. When the aggregation configuration file in the cloud is read and modified, the local aggregation configuration file is automatically updated, thus achieving real-time updates of the local aggregation configuration file.
[0106] The monitoring tool can be inotify, a Linux feature that monitors file system operations such as reads, writes, and creations. Inotify is highly responsive and very easy to use.
[0107] In practical implementation, the above-described solution in this application can be implemented by the API aggregation module. Please refer to... Figure 13 , Figure 13 The API gateway architecture diagram of this application is shown. The API aggregation function is located between the pre-filter module and the routing and forwarding module. For the specific implementation process of the API gateway, please refer to [link / reference needed]. Figure 14 , Figure 14 The diagram illustrates a timing sequence of an embodiment of this application. The API aggregation function sits between the pre-filter module and the routing forwarding module. When the front-end receives a user request, it parses the API route and API request contained in the request. The API request is forwarded to the API gateway, which determines the corresponding API aggregation type and forwards it to the back-end server. After processing by the back-end server, the API request is forwarded to the API gateway post-filter. The post-filter parses the API request into a response status and serialized data, and then passes these to the API aggregation module. The API aggregation module performs aggregation and deserialization operations on the received data and returns the aggregation result to the post-filter. The post-filter checks if the aggregation result returned by the API aggregation module matches the result determined by the API gateway. If they match, the user request is responded to. If they do not match, the forwarding operation from the API gateway to the post-filter's determination operation is repeated until a successful response is achieved or the threshold for re-operation is reached.
[0108] In summary, the API aggregation method provided in this application can use user requests and aggregation configuration files to determine the target API aggregation method, and then call the API corresponding to the target API aggregation method to respond to the user request and return the data required by the user. This allows a user request that would normally require calling multiple APIs to be fulfilled to be fulfilled by calling only one or a few APIs aggregated through the target API aggregation method, thereby improving the response rate.
[0109] Figure 15 This is a block diagram of an API aggregation apparatus according to an embodiment of this application, such as Figure 14As shown, the API aggregation device 80 includes:
[0110] Acquisition module 810; used to acquire historical business data within a first preset time period, the first preset time period including multiple unit time periods;
[0111] The target API aggregation method determination module 820 is used to decompose the historical business data to obtain the trend data and periodic data of the historical business data.
[0112] API module 830 is invoked to obtain working time trend data and non-working time trend data within the first preset time period based on the rate of change of the trend data within each unit time period.
[0113] In some embodiments of this application, the target API aggregation method determination module 820 includes: a business scenario determination module, used to determine the business scenario corresponding to the user request based on the user request; and a target API aggregation method acquisition module, used to acquire the target API aggregation method corresponding to the user request based on the determined business scenario and the correspondence between business scenarios and API aggregation methods in the aggregation configuration file.
[0114] In some embodiments of this application, the API aggregation method includes dependency aggregation and / or parallel aggregation. The pre-invocation API module 830 includes invoking a one-to-one dependency aggregation module to sequentially invoke multiple APIs, with the output of the previous API serving as the input of the next API.
[0115] In some embodiments of this application, the pre-call API module 830 further includes a call many-to-many dependency aggregation module, which is used to sequentially call a first API, a plurality of second APIs and a third API, using the output of the first API as the input of the plurality of second APIs and the output of the plurality of second APIs as the input of the third API.
[0116] In some embodiments of this application, the pre-call API module 830 further includes a parallel input aggregation module for sequentially calling a plurality of first APIs and a second API, using the outputs of the plurality of first APIs as the inputs of the second API.
[0117] In some embodiments of this application, the pre-call API module 830 further includes a call parallel merging aggregation module, which is used to sequentially call multiple first APIs and output the outputs of the multiple first APIs.
[0118] In some embodiments of this application, the API aggregation device 80 further includes a reading and parsing module for reading and parsing the aggregation configuration file; and an updating module for updating the correspondence between the business scenario and the API aggregation method according to the update information when the update information of the aggregation configuration file is obtained.
[0119] It should be noted that each module in the API aggregation device in this embodiment corresponds one-to-one with each step in the API aggregation method in the aforementioned embodiment. Therefore, the specific implementation of this embodiment can refer to the implementation of the aforementioned API aggregation method, and will not be repeated here.
[0120] It should be understood that the above are merely illustrative examples and do not constitute any limitation on the technical solution of this application. Those skilled in the art can make settings as needed in practical applications, and no restrictions are imposed here.
[0121] This application also provides a computer-readable storage medium storing computer-readable instructions thereon, which, when executed by a processor, implement the method in any of the above method embodiments.
[0122] Computer-readable storage media can be electronic storage devices such as flash memory, EEPROM (Electrically Erasable Programmable Read-Only Memory), EPROM, hard disk, or ROM. Optionally, computer-readable storage media includes non-transitory computer-readable storage media. The computer-readable storage medium has storage space for computer-readable instructions that perform any of the method steps described above. These computer-readable instructions can be read from or written to one or more computer program products. The computer-readable instructions can be compressed, for example, in a suitable form.
[0123] According to one aspect of the embodiments of this application, a computer program product or computer program is provided, the computer program product or computer program including computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, causing the computer device to perform the methods of any of the above embodiments.
[0124] It should be noted that although several modules or units for the device used to perform actions have been mentioned in the detailed description above, this division is not mandatory. In fact, according to the embodiments of this application, the features and functions of two or more modules or units described above can be embodied in one module or unit. Conversely, the features and functions of one module or unit described above can be further divided and embodied by multiple modules or units.
[0125] Through the above description of the embodiments, those skilled in the art will readily understand that the exemplary embodiments described herein can be implemented by software or by combining software with necessary hardware. Therefore, the technical solutions according to the embodiments of this application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (such as a CD-ROM, USB flash drive, external hard drive, etc.) or on a network, including several instructions to cause a computing device (such as a personal computer, server, touch terminal, or network device, etc.) to execute the method according to the embodiments of this application.
[0126] Other embodiments of this application will readily occur to those skilled in the art upon consideration of the specification and practice of the embodiments disclosed herein. This application is intended to cover any variations, uses, or adaptations of this application that follow the general principles of this application and include common knowledge or customary techniques in the art not disclosed herein.
[0127] It should be understood that this application is not limited to the precise structure described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of this application is limited only by the appended claims.
Claims
1. An API aggregation method, characterized by, The method comprises: obtaining a user request; determining a target API aggregation mode corresponding to the user request according to the user request and an aggregation configuration file, the aggregation configuration file comprising a correspondence between a business scenario and an API aggregation mode; the API aggregation mode corresponding to one business scenario indicating all APIs involved in calling under the API aggregation mode, a dependency relationship between different APIs in the APIs, and an API outputting a result; calling the APIs involved in the target API aggregation mode according to the dependency relationship between different APIs indicated by the target API aggregation mode, and obtaining data output by the API outputting a result indicated by the target API aggregation mode as data corresponding to the user request and returning the data; wherein the determining of the target API aggregation mode corresponding to the user request according to the user request and the aggregation configuration file comprises: determining a business scenario corresponding to the user request according to the user request; the user request carrying information for indicating a business scenario; obtaining the target API aggregation mode corresponding to the user request according to the determined business scenario and the correspondence between the business scenario and the API aggregation mode in the aggregation configuration file.
2. The method of claim 1, wherein, The API aggregation mode comprises a dependency aggregation mode and / or a parallel aggregation mode.
3. The method of claim 2, wherein, The dependency aggregation mode comprises a one-to-one dependency aggregation, and the calling of the APIs involved in the target API aggregation mode comprises: calling the APIs in sequence, the output of a previous API being used as the input of a next API.
4. The method of claim 2, wherein, The dependency aggregation mode comprises a many-to-many dependency aggregation, and the many-to-many dependency aggregation comprises: calling a first API, a plurality of second APIs, and a third API in sequence, the output of the first API being used as the input of the plurality of second APIs, and the output of the plurality of second APIs being used as the input of the third API.
5. The method of claim 2, wherein, The parallel aggregation mode comprises a parallel input aggregation, and the parallel input aggregation comprises: calling a plurality of first APIs and a second API in sequence, the output of the plurality of first APIs being used as the input of the second API.
6. The method of claim 2, wherein, The parallel aggregation mode comprises a parallel merge aggregation, and the parallel merge aggregation comprises: calling a plurality of first APIs in sequence, and outputting the outputs of the plurality of first APIs at the same time.
7. The method according to any one of claims 1 to 6, characterized in that, The method further comprises: reading and parsing the aggregation configuration file; when obtaining update information of the aggregation configuration file, updating the correspondence between the business scenario and the API aggregation mode according to the update information.
8. An API aggregation device, characterized by, comprise: an obtaining module configured to obtain a user request; a target API aggregation mode determining module configured to determine a target API aggregation mode corresponding to the user request according to the user request and an aggregation configuration file, the aggregation configuration file comprising a correspondence between a business scenario and an API aggregation mode; the API aggregation mode corresponding to one business scenario indicating all APIs involved in calling under the API aggregation mode, a dependency relationship between different APIs in the APIs, and an API outputting a result; The API module is called to call a plurality of APIs involved in the target API aggregation mode according to a dependency relationship between different APIs indicated by the target API aggregation mode, and obtain data output by an API indicated by the target API aggregation mode as data corresponding to the user request and return the data. The target API aggregation mode corresponding to the user request is determined according to the user request and the aggregation configuration file, including determining a business scenario corresponding to the user request according to the user request, the user request carrying information for indicating the business scenario. The target API aggregation mode corresponding to the user request is obtained according to the determined business scenario and a corresponding relationship between business scenarios and API aggregation modes in the aggregation configuration file.
9. An electronic device, comprising: Comprise: A processor; A memory, the memory has computer readable instructions stored thereon, the computer readable instructions are executed by the processor to implement the method of any one of claims 1-7.
10. A computer readable storage medium, characterized in that, The computer readable storage medium has program code stored therein, the program code can be called and executed by the processor to implement the method of any one of claims 1-7.
Citation Information
Patent Citations
Service calling method and device supporting combined API
CN111367690A
Method and device for determining dependency relationship between interfaces
CN111552509A
Business service system, business request method and gateway equipment
CN113364853A