Method, device, equipment and computer-readable medium for calling interface
By receiving the call interface request and encapsulating input parameters to the preset interface call program, the problem of needing to write RPC layer code separately in the prior art is solved, and the efficiency of interface development and the simplicity of the system is improved.
Patent Information
- Application Number
- CN202010453682.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-05-26
- Publication Date
- 2025-04-15
- Estimated Expiration
- 2040-05-26
AI Technical Summary
In the prior art, each call to a remote interface requires the writing of the code of the remote procedure call (RPC) layer, which leads to the inefficient interface development.
By receiving a call interface request, obtaining input parameters, encapsulating them in an RPC request, and sending them to a preset interface call program to call the interface, without writing RPC layer code separately.
It improves the efficiency of interface development, reduces the amount of business code, and reduces the complexity and maintenance difficulty of the system.
Smart Images

Figure CN113722115B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a method, device, equipment and computer-readable medium for calling an interface. Background Art
[0002] As the business volume increases, the business codes also continue to increase. The system becomes bloated by simply adding codes without limit.
[0003] In the process of implementing the present invention, the inventors found that there are at least the following problems in the prior art: each time a remote interface is called, the code of the remote procedure call (RPC) layer needs to be written separately, resulting in low efficiency of interface development. Summary of the invention
[0004] In view of this, the embodiments of the present invention provide a method, apparatus, device and computer-readable medium for calling an interface, which can improve the efficiency of interface development.
[0005] To achieve the above object, according to one aspect of an embodiment of the present invention, a method for calling an interface is provided, comprising:
[0006] Receive a call interface request;
[0007] Based on the parameters in the calling interface request, obtaining input parameters of the calling interface;
[0008] Encapsulating the input parameters in a remote procedure call (RPC) request and sending it to a preset interface calling program to call the interface;
[0009] The preset interface calling program successfully calls the interface and outputs the parameters fed back by the interface.
[0010] The calling interface request includes calling a Hypertext Transfer Protocol HTTP interface request;
[0011] The step of obtaining input parameters of the calling interface based on the parameters in the calling interface request includes:
[0012] The parameters in the calling interface request are used as the input parameters, and the input parameters include the input request link, HTTP request body and timeout period.
[0013] The calling interface request includes calling the RPC framework interface request;
[0014] The step of obtaining input parameters of the calling interface based on the parameters in the calling interface request includes:
[0015] The parameters in the request for calling the RPC framework interface include an interface name, and the implementation method corresponding to the interface name is loaded by using the reflection technology through the interface name, and the parameters involved in the implementation method are loaded by using the reflection technology;
[0016] The interface name, the implementation method corresponding to the interface name, and the parameters involved in the implementation method are used as the input parameters.
[0017] The RPC framework interface call request includes the following: JSF service call request, dubbo service call request and springCloud service call request.
[0018] The RPC request includes an rpcRequest object;
[0019] The output of the parameters fed back by the interface includes:
[0020] In the rpcResponse object, the parameters fed back by the interface are output.
[0021] The calling interface request includes calling HTTP interface request;
[0022] The preset interface calling program successfully calls the interface and outputs the parameters fed back by the interface, including:
[0023] Encapsulate the input parameters into an HTTP client request, and use the HTTP client request management end to call the HTTP client t to send the RPC request to the interface;
[0024] After the interface is successfully called, the parameters fed back by the interface are encapsulated and output in the rpcResponse object in the JSON data format.
[0025] The calling interface request includes calling the RPC framework interface request;
[0026] The preset interface calling program successfully calls the interface and outputs the parameters fed back by the interface, including:
[0027] According to the interface name in the input parameter, obtain the implementation method set of the interface;
[0028] Traverse the implementation method set, compare the implementation method corresponding to the interface name of the input parameter, and obtain the implementation method that needs to be requested;
[0029] Call the interface according to the implementation method of the request and the parameters involved in the implementation method corresponding to the interface name of the input parameter;
[0030] After the interface is successfully called, the parameters fed back by the interface are encapsulated and output in the rpcResponse object in the JSON data format.
[0031] According to a second aspect of an embodiment of the present invention, there is provided a device for calling an interface, including:
[0032] A receiving module, used for receiving a call interface request;
[0033] An acquisition module, used for acquiring input parameters of the calling interface based on the parameters in the calling interface request;
[0034] A calling module, used for encapsulating the input parameters in a remote procedure call (RPC) request and sending it to a preset interface calling program to call the interface;
[0035] The output module is used for the preset interface calling program to successfully call the interface and output the parameters fed back by the interface.
[0036] According to a third aspect of an embodiment of the present invention, there is provided an electronic device for calling an interface, including:
[0037] one or more processors;
[0038] a storage device for storing one or more programs,
[0039] When the one or more programs are executed by the one or more processors, the one or more processors implement the above method.
[0040] According to a fourth aspect of an embodiment of the present invention, there is provided a computer-readable medium on which a computer program is stored, and when the program is executed by a processor, the method as described above is implemented.
[0041] An embodiment of the above invention has the following advantages or beneficial effects: receiving a call interface request; obtaining input parameters of the call interface based on the parameters in the call interface request; encapsulating the input parameters in an RPC request and sending it to a preset interface call program to call the interface; the preset interface call program successfully calls the interface and outputs the parameters fed back by the interface. Since the preset interface call program can be executed to send an RPC request based on the input parameters of the call interface, and then the parameters fed back by the interface are output. There is no need to write the RPC layer code separately, so the efficiency of interface development can be improved.
[0042] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with the specific implementation manner. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.
[0044] Figure 1 This is a flowchart of APP data request;
[0045] Figure 2 is a schematic diagram of the main process of the method for calling an interface according to an embodiment of the present invention;
[0046] Figure 3 is a schematic diagram of a process of obtaining input parameters of a calling interface according to an embodiment of the present invention;
[0047] Figure 4 is a schematic diagram of parameters involved in an HTTP interface request according to an embodiment of the present invention;
[0048] Figure 5 is a schematic diagram of parameters involved in a JSF service call request according to an embodiment of the present invention;
[0049] Figure 6 It is a schematic diagram of a process for calling an interface for an HTTP interface request according to an embodiment of the present invention;
[0050] Figure 7 It is a schematic diagram of a process for calling an interface for a JSF service call request according to an embodiment of the present invention;
[0051] Figure 8 is a schematic diagram of a process flow of an APP data request according to an embodiment of the present invention;
[0052] Fig. 9 is a schematic diagram of the main structure of a device for calling an interface according to an embodiment of the present invention;
[0053] Fig.10 is an exemplary system architecture diagram to which embodiments of the present invention may be applied;
[0054] Fig.11 It is a schematic diagram of the structure of a computer system of a terminal device or a server suitable for implementing an embodiment of the present invention. DETAILED DESCRIPTION
[0055] The following is a description of 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, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may 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 of well-known functions and structures is omitted in the following description.
[0056] See also Figure 1 , Figure 1 This is a flowchart of APP data request, which includes:
[0057] The user sends a request to the client, which can be an application (APP) installed on a mobile terminal. The client sends the request to the service-oriented architecture (SOA) system on the server through the gateway.
[0058] SOA is a component model that splits different functional units of an application and connects them through well-defined interfaces and protocols between these services. The interface is defined in a neutral way and should be independent of the hardware platform, operating system, and programming language that implements the service. This allows the services of components in a variety of systems to interact in a unified and universal way.
[0059] The server-side SOA system processes requests concurrently through the view layer and the business layer. Specifically, a thread pool (ThreadPoolExcutor) is created. RPC1.executor, RPC2.executor, and RPC3.executor are processed in parallel in ThreadPoolExcutor. The above parallel processing involves the RPC layer, which mainly involves interface calls and does not perform business logic processing. Finally, the processing results are fed back to the server-side SOA system.
[0060] The server-side SOA system feeds back the parameters corresponding to the request to the user through the gateway and the client.
[0061] Currently, a separate RPC layer needs to be created for each remote service call, and RPC also needs to be configured in Spring's XML file. Spring is a lightweight open source framework in the Java EE programming field.
[0062] When Spring starts to initialize, all RPC layer codes need to be loaded into the Inversion of Control (IOC) container. It takes a long time to load a large amount of RPC layer code, which will affect the initialization of the container. Among them, IOC is the core of spring. The so-called IOC, for the Spring framework, means that Spring is responsible for controlling the life cycle of objects and the relationship between objects.
[0063] In terms of development efficiency, because each remote service call must add the corresponding RPC layer code, the interface development efficiency is reduced. In addition, the large amount of duplicate code can lead to an increase in the volume of system code, increased maintenance difficulty, and reduced code value.
[0064] Improving code reusability in the ever-increasing business code becomes increasingly important. Reusable programs and fields should be organized and modified; the remote call data layer can be optimized according to the projects involved. It can be seen that due to the duplication of RPC layer code and the large amount of code, the efficiency of interface development is low.
[0065] In order to solve the technical problem of low efficiency in interface development, the following technical solution in the embodiment of the present invention may be adopted.
[0066] See also Figure 2 , Figure 2 Schematic diagram of the main process of the method for calling an interface according to an embodiment of the present invention, encapsulating the input parameters of the calling interface in an RPC request, executing a preset interface calling program, and then outputting the parameters of the interface feedback. Figure 1 As shown, the specific steps include:
[0067] S201: Receive an interface calling request.
[0068] After the server-side SOA system receives an interface call request sent by a user, it first needs to determine the interface type.
[0069] In the embodiment of the present invention, the interface type includes a Hypertext Transfer Protocol (HTTP) interface and an RPC framework interface, wherein the RPC framework interface is an interface using an RPC framework.
[0070] As an example, the RPC framework interface call request includes one of the following requests: a JSF service call request, a dubbo service call request, and a springCloud service call request. JSF (JavaServer Faces) is a standard framework for building Java Web applications.
[0071] According to the interface calling request sent by the user, the type of the calling interface can be directly known. It can be understood that the interface type is determined by the interface calling request sent by the user.
[0072] S202: Based on the parameters in the interface calling request, obtain input parameters of the interface calling.
[0073] The call interface request includes one or more parameters, and the input parameters of the call interface are obtained based on the above parameters. The input parameters of the call interface are the parameters used to call the interface. The RPC request can be sent using the input parameters of the call interface.
[0074] Taking into account the different types of calling interfaces, the input parameters of the calling interface can be obtained according to the interface type.
[0075] For a call interface request including an HTTP interface request, method 1 may be used to obtain input parameters of the call interface. For a call interface request including an RPC framework interface request, method 2 may be used to obtain input parameters of the call interface.
[0076] Method 1
[0077] The HTTP interface request includes the input parameter request link URL, HTTP request body HTTP Body and timeout TimeOut. In order to call the interface, the parameters in the HTTP interface request can be used as input parameters for calling the interface. That is, the input parameters for calling the interface include the input parameter request link URL, HTTP Body and TimeOut.
[0078] Method 2
[0079] See also Figure 3 , Figure 3 1 is a flow chart of obtaining input parameters of a calling interface according to an embodiment of the present invention, which specifically includes:
[0080] S301. The parameters in the RPC framework interface call request include the interface name. The implementation method corresponding to the interface name and the parameters involved in the implementation method are loaded through the interface name using reflection technology.
[0081] The parameters in the request to call the RPC framework interface include the interface name. The input parameters of calling the interface need to include the interface name, the implementation method corresponding to the interface name, and the parameters involved in the implementation method corresponding to the interface name.
[0082] The implementation method corresponding to the interface name and the parameters involved in the implementation method corresponding to the interface name can be loaded through the reflection technology through the interface name.
[0083] The RPC framework interface call request includes one of the following requests: a JSF service call request, a dubbo service call request, and a springCloud service call request. The following takes the JSF service call request as an example for exemplary description.
[0084] For example, to query order information, the interface type provided by the order center is JSF type, and the interface name in the JSF service call request is com.jd.order.sdk.jsf.export.OrderCenterJsfExport. Use reflection technology to obtain the implementation method getOrderInfo(pin,orderId) corresponding to the interface name from the IOC container through the interface name, as well as the parameters OrderCenterJsfExport involved in the implementation method. Finally, use OrderCenterJsfExport to call getOrderInfo to call the JSF interface.
[0085] S302: Take the interface name, the implementation method corresponding to the interface name, and the parameters involved in the implementation method as input parameters.
[0086] The above interface name, the implementation method corresponding to the interface name and the parameters involved in the above implementation method can be used as input parameters for calling the interface to call the upstream interface.
[0087] exist Figure 3 In the embodiment, for a request to call an RPC framework interface, the reflection technology can be used to load relevant parameters, thereby obtaining input parameters of the calling interface.
[0088] S203: Encapsulate the input parameters in an RPC request and send it to a preset interface calling program to call the interface.
[0089] According to the existing development procedures, if an upstream interface needs to be called each time a new service is connected, a separate RPC layer code needs to be added for the newly connected interface, which results in repeated code writing.
[0090] In the embodiment of the present invention, for calling interface request, no matter which interface type, the interface can be called by using a preset interface calling program. That is to say, according to the input parameters of calling the interface, the RPC request can be sent to call the interface by using the preset interface calling program.
[0091] Specifically, there is no need to write code repeatedly. The input parameters of the calling interface can be uniformly encapsulated in the rpcRequest object. The input parameters in the rpcRequest object are parsed in the preset interface calling program, and then the interface is called. When the interface call is successful, the preset interface calling program uniformly encapsulates the returned parameters into the rpcResponse object.
[0092] According to the commonality of various RPC codes, the preset interface calling program can achieve the maximum reduction of the business code amount and can call the interface normally. It can be understood that the preset interface calling program is set according to the commonality of various RPC codes.
[0093] S204, the preset interface calling program successfully calls the interface and outputs the parameters fed back by the interface.
[0094] After receiving the input parameters of the calling interface, the preset interface calling program successfully calls the interface and outputs the parameters fed back by the interface. Specifically, the fed back parameters can be output to the SOA system on the server side.
[0095] In one embodiment of the present invention, the RPC request includes an rpcRequest object. Then, the parameters of the interface feedback can be output in the rpcResponse object.
[0096] See also Figure 4 , Figure 4 It is a schematic diagram of parameters involved in an HTTP interface request according to an embodiment of the present invention.
[0097] When the interface call request is an HTTP interface request, the call involves rpsRequest and rpcResponse. rpsRequest needs to encapsulate the input request link URL, input parameter Body, and timeout TimeOut. In other words, the input parameters of the call interface include the input request link URL, input parameter Body, and timeout TimeOut.
[0098] See also Figure 5 , Figure 5 It is a schematic diagram of parameters involved in a JSF service call request according to an embodiment of the present invention.
[0099] In the case where the interface call request is a JSF service call request, the call involves rpsRequest and rpcResponse. rpsRequest needs to encapsulate the interface name interfaceName, the implementation method methodName corresponding to the interface name, and the parameter requestParam involved in the implementation method. In other words, the input parameters of the interface call include interfaceName, methodName, and requestParam.
[0100] In the embodiment of the present invention, the interface is called by a preset interface calling program, and an exemplary description is given below according to the interface type.
[0101] in, Figure 6 The following description is made by taking the calling interface request as an example, that is, calling the HTTP interface request. Figure 7 The following description is made by taking the case where the interface calling request is a JSF service calling request.
[0102] See also Figure 6 , Figure 6The flowchart of calling an interface for an HTTP interface request according to an embodiment of the present invention specifically includes:
[0103] S601, encapsulate input parameters into HTTP client request, and use HTTP client request management end to call HTTP client to send RPC request to interface.
[0104] The HTTP interface request is sent to HttpRequestHandler, which parses the input request link URL, input body, and timeout TimeOut. The input request link URL, input body, and timeout TimeOut are encapsulated into rpsRequest, which is specifically an HTTP client request (HttpClie ntRequest).
[0105] Then, use the http request tool class HTTP client request manager (HttpClientRequestManager) to call the corresponding implementation method to send the HTTP client (sendHttpClient) to send the RPC request to the interface.
[0106] S602: After the interface is successfully called, the parameters of the interface feedback are encapsulated and output in the rpcResponse object in the JSON data format.
[0107] After successfully calling the interface, the parameters fed back by the interface can be received and output in the rpcResponse object in the JSON data format, and then the fed back parameters can be returned to the server-side SOA system.
[0108] JSON is a lightweight data exchange format. It is based on a subset of ECMAScript and uses a text format that is completely independent of programming languages to store and represent data. The simplicity and clear hierarchical structure make JSON an ideal data exchange language. It is easy to read and write, as well as easy for machines to parse and generate, and effectively improves network transmission efficiency.
[0109] exist Figure 6 In the embodiment, for each HTTP interface request, there is no need to repeatedly write code, and you can use Figure 6 The steps in the call interface can return the feedback parameters to the server-side SOA system.
[0110] See also Figure 7 , Figure 7The flowchart of calling the interface for a JSF service call request according to an embodiment of the present invention is as follows. The RPC framework interface request may include: a JSF service call request, a dubbo service call request or a springCloud service call request. The following is an exemplary description of the RPC framework interface request as a JSF service call request. Specifically, it includes:
[0111] S701. Obtain an interface implementation method set according to the interface name in the input parameter.
[0112] The HPPT interface request is sent to JsfRequestHandler, which parses the input parameters interfaceName, methodName, and requestParam.
[0113] Use @Autowired to load the interface class Class.forName in the IOC container according to interfaceName. At the same time, obtain the interface implementation method set according to the reflection Class.forName(String interfaceName).
[0114] S702: traverse the implementation method set, compare the implementation method corresponding to the interface name of the input parameter, and obtain the implementation method that needs to be requested.
[0115] Traverse the interface method set and compare the input parameter methodName to obtain the implementation method that needs to be requested.
[0116] S703: Call the interface according to the requested implementation method and the parameters involved in the implementation method corresponding to the interface name of the input parameter.
[0117] According to the requested implementation method and requestParam, the JSF interface is called.
[0118] S704. After the interface is successfully called, the parameters fed back by the interface are encapsulated and output in the rpcResponse object in the JSON data format.
[0119] The JSF interface feedback parameters, that is, the JSF interface is successfully called. The parameters fed back by the JSF interface are encapsulated in the rpcResponse object in JSON data format to output the parameters fed back by the interface to the server-side SOA system.
[0120] exist Figure 7 In the embodiment, for each RPC framework interface request, there is no need to repeatedly write code, and you can use Figure 7 The steps in the call interface can return the feedback parameters to the server-side SOA system.
[0121] See also Figure 8 , Figure 8 : is a schematic diagram of the process of APP data request according to an embodiment of the present invention, which specifically includes:
[0122] The user sends a request to the client, and the client sends the request to the service-oriented SOA system on the server side through the gateway.
[0123] The server-side SOA system processes requests concurrently through the view layer and the business layer. Figure 1 Instead of the method in the example above, the ThreadPoolExcutor receives the interface call request. Then, the input parameters of the interface call are obtained based on the interface type, and the output parameters can be encapsulated in the rpsRequest. The parameters returned by the preset interface call program are received in the rpcRespons, and the returned parameters can be fed back to the server-side SOA system.
[0124] The server-side SOA system feeds back the corresponding results of the request to the user through the gateway and the client.
[0125] From the above process, we can see that Figure 1 In comparison, Figure 8 The technical solution uses rpsRequest and rpcRespons to execute the preset interface calling program, eliminating the need to repeatedly write code and reducing the amount of business code.
[0126] In addition, the parameters fed back to the server-side SOA system are consistent with the parameters fed back using the existing technology, so it can be ensured that the server-side SOA system returns relevant data to the user normally.
[0127] In the above embodiment, a request for calling an interface is received; based on the parameters in the request for calling the interface, input parameters for calling the interface are obtained; the input parameters are encapsulated in an RPC request and sent to a preset interface calling program to call the interface; the preset interface calling program successfully calls the interface and outputs the parameters fed back by the interface.
[0128] When loading RPC information in the IOC container, only the preset interface caller needs to be loaded, and there is no need to load the RPC code of each interface, thus greatly reducing the loading time. This improves the system performance while reducing the access time. In addition, the reduction of RPC layer code makes the system more lightweight, simple to maintain, and increases readability. Finally, even with an increasing business volume, there is no need to add redundant RPC duplicate code, which greatly improves development efficiency and reduces the development cycle, allowing the business to quickly respond to market needs, thereby improving the efficiency of interface development. This improves the user experience overall.
[0129] See also Fig. 9 , Fig. 9is a schematic diagram of the main structure of a device for calling an interface according to an embodiment of the present invention. The device for calling an interface can implement a method for calling an interface, such as Fig. 9 As shown, the device for calling the interface specifically includes:
[0130] The receiving module 901 is used to receive an interface calling request.
[0131] The acquisition module 902 is used to acquire input parameters of the calling interface based on the parameters in the calling interface request.
[0132] The calling module 903 is used to encapsulate the input parameters in an RPC request and send it to a preset interface calling program to call the interface.
[0133] The output module 904 is used to preset the interface calling program to successfully call the interface and output the parameters fed back by the interface.
[0134] In one embodiment of the present invention, calling the interface request includes calling the HTTP interface request;
[0135] The acquisition module 902 is specifically used to use the parameters in the calling interface request as input parameters, and the input parameters include the input request link URL, the input Body and the timeout TimeOut.
[0136] In one embodiment of the present invention, calling the interface request includes calling the RPC framework interface request;
[0137] The acquisition module 902 is specifically used to call the parameters in the RPC framework interface request including the interface name, and use the reflection technology to load the implementation method corresponding to the interface name and the parameters involved in the implementation method through the interface name;
[0138] The interface name, the implementation method corresponding to the interface name, and the parameters involved in the implementation method are taken as input parameters.
[0139] In one embodiment of the present invention, the RPC framework interface call request includes one of the following: a JSF service call request, a dubbo service call request, and a springCloud service call request.
[0140] In one embodiment of the present invention, the RPC request includes an rpcRequest object;
[0141] The output module 904 is specifically used to input the parameters of the interface feedback in the rpcResponse object.
[0142] In one embodiment of the present invention, calling the interface request includes calling the HTTP interface request;
[0143] The output module 904 is specifically used to encapsulate the input parameters into HttpClientRequest, and use HttpClientRequestManager to call sendHttpClient to send the RPC request to the interface;
[0144] After the interface is successfully called, the parameters of the interface feedback are encapsulated and output in the rpcResponse object in JSON data format.
[0145] In one embodiment of the present invention, calling the interface request includes calling the RPC framework interface request;
[0146] The output module 904 is specifically used to obtain the implementation method set of the interface according to the interface name in the input parameter;
[0147] Traverse the implementation method set, compare the implementation method corresponding to the interface name of the input parameter, and get the implementation method that needs to be requested;
[0148] Call the interface according to the requested implementation method and the parameters involved in the implementation method corresponding to the interface name of the input parameter;
[0149] After the interface is successfully called, the parameters of the interface feedback are encapsulated and output in the rpcResponse object in JSON data format.
[0150] Fig.10 An exemplary system architecture 1000 is shown to which the method for calling an interface or the apparatus for calling an interface according to an embodiment of the present invention can be applied.
[0151] like Fig.10 As shown, the system architecture 1000 may include terminal devices 1001, 1002, 1003, a network 1004, and a server 1005. The network 1004 is used to provide a medium for communication links between the terminal devices 1001, 1002, 1003 and the server 1005. The network 1004 may include various connection types, such as wired, wireless communication links, or optical fiber cables, etc.
[0152] Users can use terminal devices 1001, 1002, 1003 to interact with server 1005 through network 1004 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 1001, 1002, 1003, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc. (only as examples).
[0153] The terminal devices 1001 , 1002 , and 1003 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, and desktop computers, etc.
[0154] The server 1005 may be a server that provides various services, such as a backend management server (only an example) that provides support for shopping websites browsed by users using the terminal devices 1001, 1002, and 1003. The backend management server may analyze and process the received data such as product information query requests, and feed back the processing results (such as target push information, product information - only an example) to the terminal device.
[0155] It should be noted that the method for calling an interface provided in the embodiment of the present invention is generally executed by the server 1005 , and accordingly, the device for calling an interface is generally set in the server 1005 .
[0156] It should be understood that Fig.10 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.
[0157] Reference below Fig.11 , which shows a schematic diagram of the structure of a computer system 1100 of a terminal device suitable for implementing an embodiment of the present invention. Fig.11 The terminal device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0158] like Fig.11 As shown, the computer system 1100 includes a central processing unit (CPU) 1101, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 1102 or a program loaded from a storage part 1108 into a random access memory (RAM) 1103. In the RAM 1103, various programs and data required for the operation of the system 1100 are also stored. The CPU 1101, the ROM 1102, and the RAM 1103 are connected to each other via a bus 1104. An input / output (I / O) interface 1105 is also connected to the bus 1104.
[0159] The following components are connected to the I / O interface 1105: an input section 1106 including a keyboard, a mouse, etc.; an output section 1107 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 1108 including a hard disk, etc.; and a communication section 1109 including a network interface card such as a LAN card, a modem, etc. The communication section 1109 performs communication processing via a network such as the Internet. A drive 1110 is also connected to the I / O interface 1105 as needed. A removable medium 1111, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 1110 as needed, so that a computer program read therefrom is installed into the storage section 1108 as needed.
[0160] In particular, according to the embodiments disclosed in the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program contains program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 1109, and / or installed from the removable medium 1111. When the computer program is executed by the central processing unit (CPU) 1101, the above-mentioned functions defined in the system of the present invention are executed.
[0161] It should be noted that the computer-readable medium shown in the present invention may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with 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, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present invention, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.
[0162] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0163] The modules involved in the embodiments of the present invention may be implemented in software or hardware. The modules described may also be provided in a processor. For example, they may be described as follows: a processor includes a sending unit, an acquisition unit, a determination unit, and a first processing unit. The names of these units do not, in some cases, constitute limitations on the units themselves. For example, the sending unit may also be described as a "unit that sends a request for obtaining an image to a connected server."
[0164] As another aspect, the present invention further provides a computer-readable medium, which may be included in the device described in the above embodiment; or may exist independently without being assembled into the device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by a device, the device includes:
[0165] Receive a call interface request;
[0166] Based on the parameters in the calling interface request, obtaining input parameters of the calling interface;
[0167] Encapsulating the input parameters in a remote procedure call (RPC) request and sending it to a preset interface calling program to call the interface;
[0168] The preset interface calling program successfully calls the interface and outputs the parameters fed back by the interface.
[0169] According to the technical solution of the embodiment of the present invention, a call interface request is received; based on the parameters in the call interface request, input parameters of the call interface are obtained; the input parameters are encapsulated in an RPC request and sent to a preset interface call program to call the interface; the preset interface call program successfully calls the interface and outputs the parameters fed back by the interface. Since the preset interface call program can be executed to send an RPC request based on the input parameters of the call interface, the parameters fed back by the interface are output. There is no need to write the code of the RPC layer separately, so the efficiency of interface development can be improved.
[0170] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A method for calling an interface, characterized in that: include: Receive a call interface request; Based on the parameters in the calling interface request, obtaining input parameters of the calling interface; Encapsulating the input parameters in a remote procedure call (RPC) request and sending it to a preset interface calling program to call the interface; The preset interface calling program is set according to the commonality of various RPC codes; the RPC request includes an rpcRequest object; The preset interface calling program successfully calls the interface and outputs the parameters fed back by the interface; The output of the parameters fed back by the interface includes: In the rpcResponse object, the parameters fed back by the interface are output.
2. The method for calling an interface according to claim 1, characterized in that: The calling interface request includes calling a Hypertext Transfer Protocol HTTP interface request; The step of obtaining input parameters of the calling interface based on the parameters in the calling interface request includes: The parameters in the calling interface request are used as the input parameters, and the input parameters include the input request link, HTTP request body and timeout period.
3. The method for calling an interface according to claim 1, characterized in that: The calling interface request includes calling the RPC framework interface request; The step of obtaining input parameters of the calling interface based on the parameters in the calling interface request includes: The parameters in the request for calling the RPC framework interface include an interface name, and the implementation method corresponding to the interface name is loaded by using the reflection technology through the interface name, and the parameters involved in the implementation method are loaded by using the reflection technology; The interface name, the implementation method corresponding to the interface name, and the parameters involved in the implementation method are used as the input parameters.
4. The method for calling an interface according to claim 3, characterized in that: The RPC framework interface call request includes the following: JSF service call request, dubbo service call request and springCloud service call request.
5. The method for calling an interface according to claim 1, characterized in that: The calling interface request includes calling HTTP interface request; The preset interface calling program successfully calls the interface and outputs the parameters fed back by the interface, including: Encapsulate the input parameters into an HTTP client request, and use the HTTP client request management end to call the HTTP client to send the RPC request to the interface; After the interface is successfully called, the parameters fed back by the interface are encapsulated and output in the rpcResponse object in the JSON data format.
6. The method for calling an interface according to claim 1, characterized in that: The calling interface request includes calling the RPC framework interface request; The preset interface calling program successfully calls the interface and outputs the parameters fed back by the interface, including: According to the interface name in the input parameter, obtain the implementation method set of the interface; Traverse the implementation method set, compare the implementation method corresponding to the interface name of the input parameter, and obtain the implementation method that needs to be requested; Call the interface according to the implementation method of the request and the parameters involved in the implementation method corresponding to the interface name of the input parameter; After the interface is successfully called, the parameters fed back by the interface are encapsulated and output in the rpcResponse object in the JSON data format.
7. A device for calling an interface, characterized in that: include: A receiving module, used for receiving a call interface request; An acquisition module, used for acquiring input parameters of the calling interface based on the parameters in the calling interface request; A calling module, used for encapsulating the input parameters in a remote procedure call (RPC) request and sending it to a preset interface calling program to call the interface; The preset interface calling program is set according to the commonality of various RPC codes; the RPC request includes an rpcRequest object; The output module is used for the preset interface calling program to successfully call the interface, output the parameters fed back by the interface, and, in the rpcResponse object, output the parameters fed back by the interface.
8. An electronic device for calling an interface, 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 6.
9. 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 6 is implemented.
Citation Information
Patent Citations
Service interface calling method applied to a loan aid business system and a loan aid business system
CN109377348A
Service data calling method and device, computer device and storage medium
CN111193716A