Interface calling method, device, server and computer readable storage medium
By finding and registering the maximum version number processor lower than the current version number in the interface call, the problem of repetitive work and errors in adding processors when the interface version is updated is solved, and the seamless calling and convenient version management of the interface version number are realized. .
Patent Information
- Application Number
- CN202111145387.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-09-28
- Publication Date
- 2024-09-17
- Estimated Expiration
- 2041-09-28
AI Technical Summary
In the existing technology, when the interface version is updated, a corresponding processor needs to be added for each version, resulting in increased repetitive work and error-prone problems.
By receiving the interface call request, search for the corresponding processor. If not found, search for the processor corresponding to the maximum version number lower than the current version number, call it, and register its relationship with the current version number in the mapping relationship for subsequent use. Find and use directly.
It achieves seamless calling of interface version numbers, reduces repetitive work, and improves the convenience and accuracy of interface version management.
Smart Images

Figure CN114020319B
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of system development technology, and in particular to a method, device, server and computer-readable storage medium for interface calling. Background Art
[0002] With the development of Internet technology, the development model is also constantly evolving. Most of the traditional browser / server model (Browser / Server, B / S structure) is rendered into Hypertext Markup Language (HTML) through the template engine and then directly displayed to the terminal users. Now the development of the Internet is no longer just for browser display, but to provide interfaces to various terminals, such as mobile terminals or other services, and then handle business separately. Each terminal is independent of each other. With the iteration of versions and changes in business, the previous interface may be changed. Due to the development of business, the field attributes of the interface have changed a lot. If you modify it directly on the original interface, the caller needs to modify it, which is extremely unfriendly to the caller. A good application programming interface (API) needs to ensure backward compatibility. Changes in product requirements cannot affect the normal functions of the existing version. At this time, interface version management is very important.
[0003] The current solution is to redefine a version of the interface so that the caller can specify the interfaces corresponding to the two versions respectively, so that the caller can call different versions of the interface by modifying the version number. The provider can write a new interface corresponding to the version each time the interface changes.
[0004] However, the inventor of the present invention has found that, with the above technical solution, due to the update of a major version, the version numbers on all Uniform Resource Locators (URLs) also need to be updated. For example, when upgrading the V1 version of an interface to the V2 version, all interfaces need to provide a V2 version of the processor, even if the interface has not modified any code, in order to add the URL corresponding to the version, if the processor is not added, the corresponding version of the processor cannot be found. Adding a corresponding processor for each version of the interface will generate a lot of repetitive work and is prone to errors. Summary of the invention
[0005] The purpose of the embodiments of the present invention is to provide a method, device, server and computer-readable storage medium for interface calling, which can solve the problem of needing to add a corresponding processor for each version of the interface and more conveniently manage the interface version.
[0006] To achieve the above-mentioned purpose, an embodiment of the present application provides a method for interface calling, including: S1: receiving an interface calling request; the interface calling request carries the first version number of the interface requested to be called; S2: searching for a first processor corresponding to the first version number; S3: if the first processor is not found, searching for a second processor corresponding to the second version number of the interface, and executing the call of the interface through the second processor; S4: registering the correspondence between the second processor and the first version number in a mapping relationship, and the mapping relationship is used to store the correspondence between the registered interface version number and the processor; wherein the second version number is the maximum version number lower than the first version number.
[0007] To achieve the above-mentioned purpose, an embodiment of the present application also provides an interface calling device, including: a receiving module, used to receive an interface calling request; the interface calling request carries the first version number of the interface requested to be called; a searching module, used to find a first processor corresponding to the first version number; an executing module, used to find a second processor corresponding to the second version number of the interface if the first processor is not found, and execute the call of the interface through the second processor; a registering module, used to register the correspondence between the second processor and the first version number in a mapping relationship, and the mapping relationship is used to store the correspondence between the registered interface version number and the processor; wherein the second version number is the maximum version number lower than the first version number.
[0008] To achieve the above-mentioned purpose, an embodiment of the present application also provides a server, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the above-mentioned interface calling method.
[0009] To achieve the above objectives, an embodiment of the present application further provides a computer-readable storage medium storing a computer program, which implements the above interface calling method when executed by a processor.
[0010] The method for calling an interface provided by an embodiment of the present application is that when the interface is called, after receiving the call request of the interface, the first version number of the request call interface carried in the call request is used to search for the first processor corresponding to the first version number of the interface. If the first processor is not found, it indicates that the first processor corresponding to the first version number is not provided, and the second processor corresponding to the second version number of the interface can be searched, and the call of the interface is executed by the second processor. By registering the correspondence between the second processor and the first version number in the mapping relationship to store the correspondence between the first version number and the second processor, when the first version number of the interface is called again, there is no need to search for the non-existent first processor, and the corresponding second processor can be directly found according to the stored correspondence between the first version number and the second processor, and the call of the first version number of the interface is executed by the second processor. Among them, the second version number is the maximum version number lower than the first version number, that is, the second version is closest to the first version, and the second processor corresponding to the second version number is more in line with the requirements of the first version number of the called interface. Therefore, the interface calling method provided in this embodiment can enable the first version number of the interface to be executed and called through the corresponding processor even without adding the first processor again, thereby solving the problem of needing to add a corresponding processor for each version of the interface and making it easier to manage interface versions.
[0011] In addition, the searching for the first processor corresponding to the first version number includes: searching for the processor corresponding to the first version number of the interface according to the mapping relationship; the searching for the second processor corresponding to the second version number of the interface includes: searching for the processor corresponding to the second version number of the interface according to the mapping relationship. Since the mapping relationship stores the correspondence between the registered interface version number and the processor, the processor corresponding to the interface version number can be quickly found through the mapping relationship.
[0012] In addition, the mapping relationship is a mapping relationship between the URL of the interface and the processor; the URL of the interface includes the version number and path of the interface; wherein the version number and path of the registered interface are stored in the first set, and the mapping relationship between the path of the registered interface and the processor is stored in the second set. By storing the version number and path of the registered interface in the first set, when the first processor is not found, it is convenient to find the maximum version number lower than the first version number; the mapping relationship between the path of the registered interface and the processor is stored in the second set, which is convenient to find the processor corresponding to the version of the called interface.
[0013] In addition, before receiving the interface call request, it also includes: obtaining a third set, the third set including the version numbers of all unregistered interfaces; traversing the third set, and executing S1 to S4 for each traversed unregistered interface version number. By traversing the third set and executing steps S1 to S4, the corresponding relationship between the version numbers of all unregistered interfaces and the corresponding processors is registered in advance, and after receiving the interface call request, the processor of the called interface version can be directly found to implement the interface call.
[0014] In addition, after obtaining the third set and before traversing the third set, the method further includes: sorting the version numbers of all unregistered interfaces in the third set in ascending order. By sorting the version numbers of unregistered interfaces in ascending order, it is convenient to obtain the maximum version number lower than the current version number.
[0015] In addition, the obtaining of the third set includes: obtaining a fourth set, the fourth set including the version numbers of all unregistered interfaces and the version numbers of all registered interfaces; and obtaining the third set by subtracting the first set from the fourth set. The unregistered interface version number set is obtained so that the corresponding relationship between the unregistered interface version number and the corresponding processor is registered in the mapping relationship, so that all versions of the interface have corresponding processors. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] One or more embodiments are exemplarily described by pictures in the corresponding drawings, and these exemplified descriptions do not constitute limitations on the embodiments. Elements with the same reference numerals in the drawings represent similar elements, and unless otherwise stated, the figures in the drawings do not constitute proportional limitations.
[0017] Figure 1 is a flowchart of an interface calling method provided according to an embodiment of the present invention;
[0018] Figure 2 is a schematic diagram of the workflow of an interface calling method provided according to an embodiment of the present invention;
[0019] Figure 3 is a flowchart of an interface calling method provided according to another embodiment of the present invention;
[0020] Figure 4 is a schematic diagram of an interface calling device provided according to another embodiment of the present invention;
[0021] Figure 5 is a structural diagram of a server provided according to another embodiment of the present invention. DETAILED DESCRIPTION
[0022] To make the purpose, technical scheme and advantages of the embodiments of the present invention clearer, the embodiments of the present invention will be described in detail below in conjunction with the accompanying drawings. However, it will be appreciated by those skilled in the art that in the embodiments of the present invention, many technical details are proposed in order to enable the reader to better understand the present application. However, even without these technical details and various changes and modifications based on the following embodiments, the technical scheme claimed in the present application can be implemented. The division of the following embodiments is for the convenience of description, and should not constitute any limitation on the specific implementation of the present invention. The various embodiments can be combined and referenced with each other without contradiction.
[0023] An embodiment of the present invention relates to a method for calling an interface, which is applicable to all systems developed based on SpringBoot. The implementation details of the method for calling the interface of this embodiment are described in detail below. The following content is only for the convenience of understanding the implementation details provided, and is not necessary for the implementation of this solution. The specific flow chart of the method for calling the interface of this embodiment is as follows Figure 1 As shown, including:
[0024] Step 101: Receive an interface call request.
[0025] Specifically, the interface provider receives a request from a user to call an interface, and the interface call request carries the first version number of the interface requested to be called. In this embodiment, the user may be a terminal, such as a mobile service terminal.
[0026] In one example, the interface provider is a server, and the specific workflow is as follows: Figure 2 As shown, it includes: a control processor, multiple processors, and a mapping processor. The control processor is used to receive a user's interface call request, obtain a corresponding processor according to the URL of the interface, execute the processor and return the execution result to the user; the multiple processors are used to execute the execution command issued by the control processor, that is, to execute the call of the interface, and return the execution result to the control processor; the mapping processor is used to store the processor of the interface, and return the corresponding processor to the control processor according to the request of the control processor to obtain the processor.
[0027] Step 102: Find a first processor corresponding to the first version number.
[0028] Specifically, after receiving the interface calling request sent by the user, the interface provider will search for the first processor corresponding to the first version number according to the first version number of the interface requested to be called carried in the interface calling request.
[0029] In one example, since the interface will be updated to generate different versions, each version number of the interface requires a corresponding processor to execute the call of the version number. After the control processor in the server receives the interface call request sent by the terminal, it will obtain the corresponding processor from the mapping processor according to the URL of the interface requested to be called, where the URL of the interface includes the version number and path of the interface. The mapping processor searches for the first processor corresponding to the first version number of the interface requested to be called based on the mapping relationship, where the mapping relationship is the mapping relationship between the URL of the interface and the processor. The mapping processor returns the found first processor to the control processor for the control processor to execute the first processor to implement the interface call, and returns the execution result of the interface call to the terminal.
[0030] Step 103: If the first processor is not found, then find the second processor corresponding to the second version number of the interface, and execute the call of the interface through the second processor.
[0031] Specifically, in step 102, if the mapping processor fails to find the first processor corresponding to the first version number of the interface requested to be called according to the mapping relationship, it will find the second processor corresponding to the second version number of the interface according to the mapping relationship between the URL of the interface and the processor, and return the second processor to the control processor for the control processor to execute the second processor to implement the interface call, and return the execution result of the interface call to the terminal.
[0032] Step 104: register the corresponding relationship between the second processor and the first version number into the mapping relationship.
[0033] Specifically, a method for registering a mapping relationship between an interface version number and a processor is stored in the mapping processor. In step 103, after finding the second processor corresponding to the second version number of the interface and returning the second processor to the control processor, the mapping processor will register the correspondence between the second processor and the first version number in the mapping relationship, that is, encapsulate the mapping relationship between the second processor and the first version number in the mapping processor, wherein the mapping relationship is used to store the correspondence between the registered interface version number and the processor.
[0034] In this embodiment, when the first processor corresponding to the first version number of the called interface cannot be found, the second processor corresponding to the second version number of the interface is searched, and the second version number of the interface searched is the largest version number lower than the first version number of the interface.
[0035] In the related art, when there are many versions of an interface, a corresponding processor needs to be added for each version, resulting in repetitive work. However, in the embodiment of the present invention, when the interface is called, after receiving the call request of the interface, the first version number of the interface is called according to the first version number of the interface carried in the call request, and the first processor corresponding to the first version number of the interface is searched. If the first processor is not found, it indicates that the first processor corresponding to the first version number is not provided, and the second processor corresponding to the second version number of the interface can be searched, and the call of the interface is executed by the second processor. By registering the correspondence between the second processor and the first version number in the mapping relationship to store the correspondence between the first version number and the second processor, when the first version number of the interface is called again, there is no need to search for the non-existent first processor, and the corresponding second processor can be directly found according to the stored correspondence between the first version number and the second processor, and the call of the first version number of the interface is executed by the second processor. Among them, the second version number is the maximum version number lower than the first version number, that is, the second version is closest to the first version, and the second processor corresponding to the second version number is more in line with the requirements of the first version number of the called interface. Therefore, the interface calling method provided in this embodiment can enable the first version number of the interface to be executed and called through the corresponding processor even without adding the first processor again, thereby solving the problem of needing to add a corresponding processor for each version of the interface and making it easier to manage interface versions.
[0036] Another embodiment of the present invention relates to a method for calling an interface, which is applicable to all systems developed based on SpringBoot. The implementation details of the method for calling the interface of this embodiment are described in detail below. The following content is only for the convenience of understanding the implementation details provided, and is not necessary for the implementation of this solution. The specific flow chart of the method for calling the interface of this embodiment is as follows: Figure 3 As shown, including:
[0037] Step 301, obtain the version number set of all registered interfaces.
[0038] Specifically, the interface provider injects the mapping processor through the SpringIOC container, traverses the mapping processor to obtain the URLs and processors of all registered interfaces. The SpringIOC container is used to manage the dependencies between objects. By injecting the SpringIOC container to complete the injection of phenomena, the application can be liberated from complex object dependencies. In this embodiment, the SpringIOC container is used to liberate the registered URLs and processors.
[0039] According to the URLs and processors of all registered interfaces obtained, the URLs of the registered interfaces are divided into version numbers and paths, and the version numbers and paths of the registered interfaces are stored in the first set, and the mapping relationship between the paths of the registered interfaces and the processors is stored in the second set. By storing the version numbers and paths of the registered interfaces in the first set, when the first processor is not found, it is convenient to find the maximum version number lower than the first version number; the mapping relationship between the paths of the registered interfaces and the processors is stored in the second set, which is convenient to find the processor of the corresponding version of the called interface.
[0040] Step 302: Obtain the version number set of all unregistered interfaces.
[0041] Specifically, the interface provider obtains all the interface version number sets from the system, namely the fourth set, which includes the version numbers of all unregistered interfaces and the version numbers of all registered interfaces. By subtracting the first set from the fourth set, the third set can be obtained, which includes the version numbers and paths of all unregistered interfaces.
[0042] Step 303: sort the version numbers of all unregistered interfaces in the third set in ascending order.
[0043] Step 304, traverse the sorted third set.
[0044] Specifically, the interface provider traverses the sorted third set, and executes steps 305 to 307 for each version number of the unregistered interface traversed.
[0045] Step 305: Receive an interface call request.
[0046] Step 306: Find the first processor corresponding to the first version number.
[0047] Step 307: If the first processor is not found, then find the second processor corresponding to the second version number of the interface, and execute the call of the interface through the second processor.
[0048] Step 308: register the correspondence between the second processor and the first version number into the mapping relationship.
[0049] Steps 305 to 308 are substantially the same as steps 101 to 104 and are not described in detail here.
[0050] It is worth mentioning that in this embodiment, in order to enable all unregistered interface versions to find the corresponding processor when they are called, after obtaining the version numbers of all unregistered interfaces in step 303, steps 305 to 308 will be repeated until all unregistered version numbers are registered, that is, the correspondence between the version numbers of all unregistered interfaces and the corresponding processors is registered in the mapping relationship.
[0051] This embodiment is substantially the same as the first embodiment, except that before receiving an interface call request, a set of unregistered interface version numbers is obtained so that the correspondence between the unregistered interface version numbers and the corresponding processors can be registered in a mapping relationship. Furthermore, by sorting the unregistered interface version numbers in ascending order, it is convenient to obtain the maximum version number lower than the current version number, so that when the processor with the first version number cannot be found, the processor with the second version number can be obtained.
[0052] The step division of the above methods is only for the purpose of clear description. When implemented, they can be combined into one step or some steps can be split and decomposed into multiple steps. As long as they include the same logical relationship, they are all within the scope of protection of this patent; adding insignificant modifications to the algorithm or process or introducing insignificant designs without changing the core design of the algorithm and process are all within the scope of protection of this patent.
[0053] Another embodiment of the present invention relates to an interface calling device. The details of the interface calling device of this embodiment are specifically described below. The following content is only for the convenience of understanding the implementation details provided, and is not necessary for implementing this example. Figure 4 It is a schematic diagram of the interface calling method described in this embodiment, including: a receiving module 401, a searching module 402, an executing module 403 and a registering module 404.
[0054] Specifically, the receiving module 401 is used to receive an interface calling request, wherein the interface calling request carries the first version number of the interface requested to be called.
[0055] In one example, before receiving the interface call request, the method further includes: obtaining a third set, wherein the third set includes version numbers of all unregistered interfaces.
[0056] The search module 402 is configured to search for a first processor corresponding to the first version number.
[0057] In one example, searching for a first processor corresponding to a first version number includes: searching for a processor corresponding to the first version number of an interface according to a mapping relationship; searching for a second processor corresponding to a second version number of an interface includes: searching for a processor corresponding to the second version number of an interface according to a mapping relationship.
[0058] The execution module 403 is used to search for a second processor corresponding to the second version number of the interface if the first processor is not found, and execute the call of the interface through the second processor.
[0059] The registration module 404 is used to register the correspondence between the second processor and the first version number into a mapping relationship, and the mapping relationship is used to store the correspondence between the registered interface version number and the processor; wherein the second version number is the maximum version number lower than the first version number.
[0060] It is not difficult to find that this embodiment is a device embodiment corresponding to the first embodiment, and this embodiment can be implemented in conjunction with the first embodiment. The relevant technical details mentioned in the first embodiment are still valid in this embodiment, and in order to reduce repetition, they are not repeated here. Accordingly, the relevant technical details mentioned in this embodiment can also be applied in the first embodiment.
[0061] It is worth mentioning that all modules involved in this embodiment are logic modules. In practical applications, a logic unit can be a physical unit, a part of a physical unit, or a combination of multiple physical units. In addition, in order to highlight the innovative part of the present invention, this embodiment does not introduce units that are not closely related to solving the technical problem proposed by the present invention, but this does not mean that there are no other units in this embodiment.
[0062] Another embodiment of the present invention relates to a server, such as Figure 5 As shown, it includes: at least one processor 501; and a memory 502 that is communicatively connected to the at least one processor 501; wherein the memory 502 stores instructions that can be executed by the at least one processor 501, and the instructions are executed by the at least one processor 501 so that the at least one processor 501 can execute the interface calling method in the above-mentioned embodiments.
[0063] Among them, the memory and the processor are connected in a bus manner, and the bus may include any number of interconnected buses and bridges, and the bus connects various circuits of one or more processors and memories together. The bus can also connect various other circuits such as peripherals, voltage regulators, and power management circuits, which are well known in the art and are therefore not further described herein. The bus interface provides an interface between the bus and the transceiver. The transceiver can be one element or multiple elements, such as multiple receivers and transmitters, providing a unit for communicating with various other devices on a transmission medium. The data processed by the processor is transmitted on a wireless medium via an antenna, and further, the antenna also receives data and transmits the data to the processor.
[0064] The processor is responsible for managing the bus and general processing, and can also provide various functions, including timing, peripheral interfaces, voltage regulation, power management, and other control functions. Memory can be used to store data used by the processor when performing operations.
[0065] Another embodiment of the present invention relates to a computer-readable storage medium storing a computer program, which implements the above method embodiment when executed by a processor.
[0066] That is, those skilled in the art can understand that all or part of the steps in the above-mentioned embodiment method can be completed by instructing the relevant hardware through a program, and the program is stored in a storage medium, including several instructions to enable a device (which can be a single-chip microcomputer, chip, etc.) or a processor to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes.
[0067] Those skilled in the art will appreciate that the above-mentioned embodiments are specific examples for implementing the present invention, and in actual applications, various changes may be made thereto in form and detail without departing from the spirit and scope of the present invention.
Claims
1. A method for interface calling, characterized in that: include: S1: receiving interface call request; The interface call request carries the first version number of the interface requested to be called; S2: searching for a first processor corresponding to the first version number; S3: If the first processor is not found, searching for a second processor corresponding to the second version number of the interface, and executing the call of the interface through the second processor; S4: registering the correspondence between the second processor and the first version number into a mapping relationship, where the mapping relationship is used to store the correspondence between the registered interface version number and the processor; The second version number is the largest version number lower than the first version number; The mapping relationship is a mapping relationship between the URL of the interface and the processor; the URL of the interface includes the version number and path of the interface; The version number and path of the registered interface are stored in the first set, and the mapping relationship between the path of the registered interface and the processor is stored in the second set; Before receiving the interface call request, the method further includes: Obtain a third set, wherein the third set includes version numbers and paths of all unregistered interfaces; Traversing the third set, and executing S1 to S4 for each traversed unregistered interface version number; The obtaining of the third set includes: Obtain a fourth set, wherein the fourth set includes version numbers and paths of all interfaces; The third set is obtained by subtracting the first set from the fourth set.
2. The method for interface calling according to claim 1, characterized in that: The searching for the first processor corresponding to the first version number includes: According to the mapping relationship, searching for a processor corresponding to the first version number of the interface; The searching for the second processor corresponding to the second version number of the interface includes: According to the mapping relationship, a processor corresponding to the second version number of the interface is searched.
3. The method for interface calling according to claim 1, characterized in that: After acquiring the third set and before traversing the third set, the method further includes: The version numbers of all unregistered interfaces in the third set are sorted in ascending order.
4. An interface calling device, characterized in that: include: A receiving module, used for receiving an interface call request; The interface call request carries the first version number of the interface requested to be called; A search module, used to search for a first processor corresponding to the first version number; an execution module, configured to search for a second processor corresponding to the second version number of the interface if the first processor is not found, and execute the call of the interface through the second processor; A registration module, used to register the correspondence between the second processor and the first version number in a mapping relationship, wherein the mapping relationship is used to store the correspondence between the registered interface version number and the processor; wherein the second version number is the maximum version number lower than the first version number; The mapping relationship is a mapping relationship between the URL of the interface and the processor; the URL of the interface includes the version number and path of the interface; The version number and path of the registered interface are stored in the first set, and the mapping relationship between the path of the registered interface and the processor is stored in the second set; The device obtains a third set before the receiving module receives the interface call request, the third set including the version numbers and paths of all unregistered interfaces; traverses the third set, and processes each traversed unregistered interface version number using the receiving module, the searching module, the executing module and the registering module; The obtaining of the third set includes: Obtain a fourth set, wherein the fourth set includes version numbers and paths of all interfaces; The third set is obtained by subtracting the first set from the fourth set.
5. A server, characterized in that: include: at least one processor; as well as, a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute the interface calling method as described in any one of claims 1 to 3.
6. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the method for interface calling according to any one of claims 1 to 3 is implemented.
