Interface calling packaging method, system and equipment and computer readable storage medium
The parameters and return results are encapsulated by calling the encapsulation method through the interface, which solves the asynchronous redundant code problem caused by the axios library in JavaScript, and achieves more efficient network resource management and computing resource optimization.
Patent Information
- Application Number
- CN202411088044.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-09
- Publication Date
- 2024-12-13
AI Technical Summary
In the prior art, the axios library used in JavaScript only encapsulates the request method path, and does not perform systematic encapsulation of parameters and return results, resulting in a large amount of asynchronous redundant code during code debugging and running.
Provide an interface call encapsulation method, instantiate the encapsulation call class, define the network request address object, check the request parameters and status code parameters, determine whether the parameters meet the preset requirements, initiate a network request, and push an exception if it does not. And end the task to implement system encapsulation of parameters and returns results.
It reduces the generation of redundant code, manages network requests in a unified and centralized manner, establishes a complete asynchronous processing system, optimizes network resource requests, and reduces waste of computing resources.
Smart Images

Figure CN119127344A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of intelligent store patrol technology, and in particular to an interface call encapsulation method, device, equipment and computer-readable storage medium. Background Art
[0002] In the prior art, front-end R&D mainly relies on https for data transmission, and uses a third-party axios library based on httprequest in JavaScript. However, the axios library only encapsulates the request method path, and does not achieve system encapsulation for parameters and return results when requesting a certain interface, resulting in a large amount of asynchronous redundant code being generated regardless of code debugging and running success or failure. In view of this, how to solve the problem of redundant code generation caused by system encapsulation has become a technical problem that needs to be solved urgently by those skilled in the art. Summary of the invention
[0003] The purpose of this application is to provide an interface call encapsulation method, device, equipment and computer-readable storage medium, which can efficiently implement interface call encapsulation and more reasonably implement task allocation.
[0004] In order to solve the above technical problems, the present application provides an interface call encapsulation method, including:
[0005] Instantiate the encapsulation calling class;
[0006] Call the execution method to initiate a request to trigger a data acquisition transaction and obtain database data;
[0007] Receive the request, obtain data, define the network request address object storage path parameters, check the interface parameters of the request parameters and the status code parameters, and execute the method of the calling class;
[0008] When executing the calling class method, determine whether the parameters meet the preset requirements. If so, initiate a network request, define the interface parameters for checking the returned results, and determine whether the results are correct; if not, push an exception and end the current task.
[0009] In some embodiments, when the calling class is instantiated and encapsulated, the method of the calling class is implemented, a base class, a base class subclass, and an exception class are defined, and the method of the calling class includes a process for initiating a network request.
[0010] In some embodiments, the triggering data acquisition transaction includes acquiring organizational structure, store, region or equipment and time node data indicators.
[0011] In some embodiments, the triggering data acquisition transaction includes acquiring organizational structure, store, region or equipment and time node data indicators.
[0012] In some embodiments, the data indicator is a single data indicator or multiple data indicators. When a single indicator is selected, the current page displays the database data of the single data after acquiring the data. When an associated indicator is selected, the current page displays the database data of the associated data after acquiring the data.
[0013] In some embodiments, the database data includes tabular data, statistical data and / or graphical data.
[0014] In some embodiments, the determination of whether the parameters meet the preset requirements is based on a standard interface document.
[0015] In some embodiments, before calling an execution method to initiate a request to trigger a data acquisition transaction to acquire database data, the user configures parameters. The configured parameters are used as parameters to be judged when executing the calling class method and are compared and judged with the parameters in the standard interface document.
[0016] In order to solve the above technical problems, the present application also provides an interface call encapsulation system, including:
[0017] Encapsulation module, used to instantiate the encapsulation calling class;
[0018] The request module is used to call the execution method to initiate a request in order to trigger a data acquisition transaction and obtain database data;
[0019] An execution module, used to receive the request, obtain data, define the network request address object storage path parameters, check the interface parameters of the request parameters and the status code parameters, and execute the method of the calling class;
[0020] The judgment module is used to judge whether the parameters meet the preset requirements when executing the calling class method. If they meet the requirements, a network request is initiated, the interface parameters for checking the returned results are defined, and the results are judged to be correct; if they do not meet the requirements, an exception is pushed and the current task is terminated.
[0021] In order to solve the above technical problems, the present application also provides an interface call encapsulation device, including:
[0022] Memory for storing computer programs;
[0023] The processor is used to implement the steps of the interface call encapsulation method as described above when executing the computer program.
[0024] In order to solve the above technical problems, the present application also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the interface call encapsulation method described above are implemented.
[0025] The present application proposes an interface call encapsulation method, apparatus, device and computer-readable storage medium, which implements system encapsulation of parameters and return results when requesting an interface, calls an execution method to initiate a request, triggers a data acquisition transaction to acquire database data, defines a network request address object storage path parameter, checks the interface parameters of the request parameters and a status code parameter, executes a method of a call class, determines whether the parameters meet the preset requirements according to a standard interface document, initiates a network request if they meet, defines interface parameters for checking the return result and determines whether the result is correct, and pushes an exception and terminates the current task if they do not meet the requirements.
[0026] This application implements system encapsulation of parameters and return results when requesting the interface, reduces the generation of redundant code, centrally manages network requests, and establishes a complete asynchronous processing system to ensure that requests and responses are processed within the expected range. This application optimizes network resource requests and reduces the waste of computing resources.
[0027] The interface call encapsulation device, equipment and computer-readable storage medium provided in this application all have the above-mentioned technical effects. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the prior art and the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0029] Figure 1 A flowchart of an interface calling encapsulation method provided in an embodiment of the present application;
[0030] Figure 2 A software interface diagram of an interface calling encapsulation method provided in an embodiment of the present application;
[0031] Figure 3 A schematic diagram of an interface call encapsulation system provided in an embodiment of the present application;
[0032] Figure 4 A schematic diagram of an interface calling encapsulation device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0033] The core of this application is to provide an interface call encapsulation method, device, equipment and computer-readable storage medium, which can efficiently implement interface call encapsulation and more reasonably implement task allocation.
[0034] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0035] Specifically, please refer to Figure 1 , Figure 1 A flowchart of an interface call encapsulation method provided in an embodiment of the present application is provided. Figure 1 As shown, the method includes:
[0036] S101, instantiate the encapsulation calling class;
[0037] In this embodiment, a packaged call class is instantiated, the call class class name is MyAjax class, and the MyAjax class is implemented to wait for the call execution of the instantiated package class. Specifically, when implementing the MyAjax class, a normal base class Base is defined, and a normal subclass Api is defined by inheriting the normal base class Base. An exception class BaseExc is defined, which inherits the Error class, and an exception subclass Flow is defined by inheriting the exception class BaseExc.
[0038] The MyAjax base class is defined based on the normal subclass Api and the abnormal subclass Flow. When the MyAjax base class is called and executed, it includes defining the apis object to store the Ajax path, defining the map for checking the request parameters, and defining the status code, etc. Each method of the MyAjax class will determine whether the parameters meet the preset requirements, so as to initiate a real request and execute the corresponding program flow.
[0039] S102, calling an execution method to initiate a request, so as to trigger a data acquisition transaction and acquire database data;
[0040] In this embodiment, if Figure 2 As shown, click the query function key to call the execution method in the project, such as the get and put methods for obtaining information, which are used to initiate Ajax requests for network communication requests, trigger data acquisition transactions, and thus obtain database data. Figure 2 As shown, the database data obtained by this application can be tabular data, statistical data, chart data, etc.
[0041] In some embodiments, taking the "query" function as an example, the user can select an organizational structure, store, region or equipment, and can query by fuzzy query when selecting. When configuring the query parameters, you can choose to query with "hour", "day", "week", "month", "quarter", "year" and "holiday" as time nodes. When choosing to query with "hour" as the time node, you can choose the time range, for example, 9:00 to 23:00. It should be noted that when configuring the query parameters, you can choose single indicators and related indicators. When selecting single indicators, you can choose the length of stay, near-point passenger flow, passenger flow, store passenger flow, store passenger flow, store passenger flow, store entry rate, effective passenger flow, sales, number of orders, etc.; when selecting related indicators, you can choose "store passenger flow-store passenger flow-store entry rate", "number of orders-store passenger flow-transaction rate", etc., of course, the related indicators can also be two or more indicators. It should be emphasized that when a single indicator is selected, the current page displays the chart data of the single data after obtaining the data; when an associated indicator is selected, the current page displays the chart data of the associated data after obtaining the data.
[0042] S103, receiving the request, acquiring data, defining the network request address object storage path parameters, checking the interface parameters of the request parameters and the status code parameters, and executing the method of the calling class;
[0043] In this embodiment, based on axios to obtain data, define an apis object to store the Ajax path, define a map to check request parameters, and define a status code. Among them, the apis object is the network request address, the map is the parameters required by each interface, and the status code is a custom and predictable error code. When an Ajax request is received, the request parameter map is triggered.
[0044] S104, when executing the calling class method, determine whether the parameters meet the preset requirements. If they meet the requirements, initiate a network request, define the interface parameters for checking the returned results and determine whether the results are correct; if they do not meet the requirements, push an exception and end the current task.
[0045] In this embodiment, it is determined whether the parameters meet the preset requirements. If so, the actual request for this call is initiated, that is, the front end initiates a network request, defines a Map to check the returned result, and determines whether the result is correct. If the result is correct, the execution is terminated. If not, an exception is pushed.
[0046] It should be noted that in this embodiment, whether the judgment parameters meet the preset requirements is based on the standard interface document. Before calling the execution method to initiate a request to trigger the data acquisition transaction to obtain database data, the user configures the parameters. The configured parameters are used as parameters to be judged when executing the call class method, and are compared and judged with the parameters in the standard interface document. In this embodiment, taking the "query" function as an example, the parameters are configured before the query, the store is selected to obtain the store ID, the specific start time and the specific end time are selected to obtain the time interval, etc., click the query function key to initiate the request, obtain the data, and define the network request address object storage path parameters, the interface parameters for checking the request parameters, and the status code parameters, and then execute the call class method to determine whether the parameters to be judged meet the parameter requirements in the standard interface document. If they meet, the front end initiates a network request to execute the definition to check the returned result Map to determine whether the result is correct. If the result is correct, the execution ends.
[0047] In summary, in the prior art, it is necessary to obtain the interface provided by the server through axios calls, and no verification processing such as parameter verification and expected results will be performed, which will generate a large amount of asynchronous redundant code, resulting in a huge memory footprint of the entire system. This application proposes a method based on interface call encapsulation, which implements system encapsulation of parameters and return results when requesting an interface, reduces the generation of redundant code, centrally manages network requests, and establishes a complete asynchronous processing system to ensure that requests and responses are processed within the expected range. This application optimizes network resource requests and reduces the waste of computing resources.
[0048] This application proposes an interface call encapsulation method, which implements system encapsulation of parameters and return results when requesting an interface, calls an execution method to initiate a request, triggers a data acquisition transaction to obtain database data, defines the network request address object storage path parameters, checks the interface parameters of the request parameters, and the status code parameters, executes the method of the call class, and determines whether the parameters meet the preset requirements according to the standard interface document. If they meet, a network request is initiated, and the interface parameters for checking the return results are defined and judged whether the results are correct. If they do not meet the requirements, an exception is pushed and the current task is terminated. This application performs system encapsulation of parameters and return results, greatly reducing the generation of redundant code and the waste of computing resources.
[0049] The present application also provides an interface call encapsulation system, and the system described below can be referenced in correspondence with the method described above. Figure 3 , Figure 3 A schematic diagram of an interface call encapsulation system provided in an embodiment of the present application, combined with Figure 3 As shown, the system includes:
[0050] Encapsulation module, used to instantiate the encapsulation calling class;
[0051] The request module is used to call the execution method to initiate a request in order to trigger a data acquisition transaction and obtain database data;
[0052] An execution module, used to receive the request, obtain data, define the network request address object storage path parameters, check the interface parameters of the request parameters and the status code parameters, and execute the method of the calling class;
[0053] The judgment module is used to judge whether the parameters meet the preset requirements when executing the calling class method. If they meet the requirements, a network request is initiated, the interface parameters for checking the returned results are defined, and the results are judged to be correct; if they do not meet the requirements, an exception is pushed and the current task is terminated.
[0054] The interface call encapsulation system provided in the present application includes an encapsulation module, a request module, an execution module and a judgment module. The system encapsulates the call class, initiates a request to trigger a data acquisition transaction to obtain database data, defines the network request address object storage path parameters, checks the interface parameters of the request parameters and the status code parameters and executes the method implemented in the call class. If the parameters meet the requirements, a network request is initiated, and the interface parameters for checking the returned results are defined to determine whether the results are correct. Otherwise, an exception is pushed and the current task ends.
[0055] This application also provides an interface calling encapsulation device, reference Figure 4 As shown, the device includes a memory 1 and a processor 2 .
[0056] Memory 1, used for storing computer programs;
[0057] Processor 2 is used to execute the computer program to implement the following steps:
[0058] Instantiate the encapsulated calling class and call the execution method to initiate a request to trigger a data acquisition transaction and obtain database data;
[0059] Receive the request, obtain data, define the network request address object storage path parameters, check the interface parameters of the request parameters and the status code parameters, and execute the method of the calling class;
[0060] When executing the calling class method, determine whether the parameters meet the preset requirements. If so, initiate a network request, define the interface parameters for checking the returned results, and determine whether the results are correct; if not, push an exception and end the current task.
[0061] For an introduction to the equipment provided in this application, please refer to the above method embodiments, and this application will not go into details here.
[0062] The present application also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the following steps can be implemented:
[0063] Instantiate the encapsulated calling class and call the execution method to initiate a request to trigger a data acquisition transaction and obtain database data;
[0064] Receive the request, obtain data, define the network request address object storage path parameters, check the interface parameters of the request parameters and the status code parameters, and execute the method of the calling class;
[0065] When executing the calling class method, determine whether the parameters meet the preset requirements. If so, initiate a network request, define the interface parameters for checking the returned results, and determine whether the results are correct; if not, push an exception and end the current task.
[0066] The computer-readable storage medium may include: a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and other media that can store program codes.
[0067] For an introduction to the computer-readable storage medium provided in this application, please refer to the above method embodiment, and this application will not go into details here.
[0068] The various embodiments in the specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referred to each other. For the system, device, and computer-readable storage medium disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the description is relatively simple, and the relevant parts can be referred to the method part description.
[0069] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0070] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be implemented directly using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
[0071] The interface call encapsulation method, system, device and computer-readable storage medium provided by the present application are described in detail above. Specific examples are used herein to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method and core idea of the present application. It should be pointed out that for ordinary technicians in this technical field, without departing from the principles of the present application, several improvements and modifications can be made to the present application, and these improvements and modifications also fall within the scope of protection of the claims of the present application.
Claims
1. An interface call encapsulation method, characterized in that: include: Instantiate the encapsulation calling class; Call the execution method to initiate a request to trigger a data acquisition transaction and obtain database data; Receive the request, obtain data, define the network request address object storage path parameters, check the interface parameters of the request parameters and the status code parameters, and execute the method of the calling class; When executing the calling class method, determine whether the parameters meet the preset requirements. If so, initiate a network request, define the interface parameters for checking the returned results, and determine whether the results are correct; if not, push an exception and end the current task.
2. The interface call encapsulation method according to claim 1, characterized in that: When the calling class is instantiated and encapsulated, the method of the calling class is implemented, the base class, the base class subclass, and the exception class are defined, and the method of the calling class includes the process of initiating a network request.
3. The interface call encapsulation method according to claim 1, characterized in that: The triggering data acquisition transaction includes acquiring organizational structure, store, region or equipment and time node data indicators.
4. The interface call encapsulation method according to claim 3, characterized in that: The data indicator is a single data indicator or multiple data indicators. When a single indicator is selected, the current page displays the database data of the single data after obtaining the data. When an associated indicator is selected, the current page displays the database data of the associated data after obtaining the data.
5. The interface call encapsulation method according to claim 4, characterized in that: The database data includes tabular data, statistical data and / or graphical data.
6. The interface call encapsulation method according to claim 1, characterized in that: The determination of whether the parameters meet the preset requirements is based on the standard interface document.
7. The interface call encapsulation method according to claim 6, characterized in that: Before calling the execution method to initiate a request to trigger a data acquisition transaction to acquire database data, the user configures parameters. The configured parameters are used as parameters to be judged when executing the calling class method and are compared with the parameters in the standard interface document.
8. An interface call encapsulation system, characterized in that: include: Encapsulation module, used to instantiate the encapsulation calling class; The request module is used to call the execution method to initiate a request in order to trigger a data acquisition transaction and obtain database data; An execution module, used to receive the request, obtain data, define the network request address object storage path parameters, check the interface parameters of the request parameters and the status code parameters, and execute the method of the calling class; The judgment module is used to judge whether the parameters meet the preset requirements when executing the calling class method. If they meet the requirements, a network request is initiated, the interface parameters for checking the returned results are defined, and the results are judged to be correct; if they do not meet the requirements, an exception is pushed and the current task is terminated.
9. An interface call encapsulation device, characterized in that: include: Memory for storing computer programs; A processor, configured to implement the steps of the interface call encapsulation method as described in any one of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the interface call encapsulation method according to any one of claims 1 to 7 are implemented.
