Method, system and equipment for dynamically generating data service SDK (Software Development Kit) based on template
The data service SDK is dynamically generated through templates, which solves the problems of inconvenient and low efficiency API interface docking operations, realizes efficient and convenient API interface calls, simplifies the SDK development and upgrade process, and improves the efficiency of batch interface docking.
Patent Information
- Application Number
- CN202410913649.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-09
- Publication Date
- 2024-10-15
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Existing API interface docking has problems such as inconvenient operation, low efficiency, and difficulty in development. Especially in large-volume API interface usage scenarios, it is difficult to build a bridge between API gateways and consumers through toolkits.
Through the method of dynamically generating data service SDK based on templates, the SDK template project is built according to the interface protocol, the API interface information is obtained, mapped to the interface parameter template and method template, the Java source file is generated, compiled and packaged, the SDK is output, and the API interface is simplified. Calling process.
It improves the efficiency of SDK development and upgrade, significantly improves the docking efficiency and convenience of API interface, especially in batch usage scenarios, and simplifies the operation process of interface consumers.
Smart Images

Figure CN118778935A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of API interface docking, and in particular to a method, system and device for dynamically generating a data service SDK based on a template. Background Art
[0002] Currently, the data service platform publishes the interface to the API gateway by providing third-party interface hosting and codeless API development, and then users apply for and obtain the interface call documents and examples on the service platform, that is, the use of the interface depends on the call documents and examples. Although users can use the API interface applied for from the data service platform, in actual applications, there are the following shortcomings: 1. After obtaining the call document, the interface consumer needs to perform interface joint debugging according to the call information provided in the document. The operation of accessing the API interface is inconvenient, and it is easy to make mistakes if the document and examples are not carefully read; 2. In the scenario of using a large number of API interfaces, although the data service platform provides call documents and examples, the consumer needs to access the API interface one by one, and the docking efficiency is low; 3. Because the API interfaces are different, converting the call logic of each interface into a specific binary file and then writing it into the toolkit is difficult to develop and maintain, and it is impossible to build a bridge between the API gateway interface and the consumer through the toolkit (SDK).
[0003] Therefore, how to provide a more efficient and accurate API interface docking method has become a technical problem that needs to be solved urgently. Summary of the invention
[0004] In view of this, in order to overcome the deficiencies of the prior art, the present invention aims to provide a method, system and device for dynamically generating a data service SDK based on a template.
[0005] According to a first aspect of the present invention, there is provided a method for dynamically generating a data service SDK based on a template, comprising:
[0006] Build an SDK template project according to the interface protocol to obtain the API interface information authorized by the data service platform;
[0007] By mapping the obtained API interface information to the created interface parameter template and interface method template, Java source files of the SDK interface class and interface parameter class are generated;
[0008] Generate the corresponding calss files by converting and compiling the Java source files of SDK interface class and interface parameter class;
[0009] Create an interface using jar according to the class file and SDK template project, and generate and output SDK using jar according to the created interface.
[0010] Preferably, in the method of dynamically generating a data service SDK based on a template of the present invention, an SDK template project is constructed according to an interface protocol, including: constructing a corresponding SDK template project by matching calling methods, configurations and dependencies for the interface protocol.
[0011] Preferably, in the method of dynamically generating a data service SDK based on a template of the present invention, the API interface information includes an interface call URL, a request method, a media type, an interface parameter structure and an authorization token.
[0012] Preferably, in the method of dynamically generating a data service SDK based on a template of the present invention, Java source files of the SDK interface class and interface parameter class are generated by mapping the acquired API interface information to the created interface parameter template and interface method template, including: creating an interface parameter template and an interface method template, and generating Java source files of the SDK interface class and interface parameter class by mapping the acquired API interface information to the created interface parameter template and interface method template.
[0013] Preferably, in the method of dynamically generating a data service SDK based on a template of the present invention, Java source files of the SDK interface class and the interface parameter class are generated by mapping the acquired API interface information to the created interface parameter template and interface method template, including: creating an interface parameter template and an interface method template respectively through the FreeMarker template language, mapping the API interface information to the created interface parameter template and interface method template respectively through a template engine tool, and generating Java source files of the SDK interface class and the interface parameter class.
[0014] Preferably, in the method of dynamically generating a data service SDK based on a template of the present invention, the Java source files of the SDK interface class and the interface parameter class are converted and compiled to generate corresponding calss files, including: converting the Java source files of the SDK interface class and the interface parameter class into file objects, converting the file objects to be compiled into compilation units through a file manager, building a compilation task for the compilation unit obtained by the conversion, using a JavaCompiler compilation tool to execute the compilation task, and obtaining the corresponding class file.
[0015] Preferably, in the method of dynamically generating a data service SDK based on a template of the present invention, an interface usage jar is created according to a class file and an SDK template project, including: creating a target file corresponding to the interface usage jar, and writing the compiled class file and the constructed SDK template project into the created target file by sequentially using the JarOutputStream file output stream to create an interface usage jar.
[0016] Preferably, in the method of dynamically generating a data service SDK based on a template of the present invention, the SDK is generated and output using jar according to the created interface, including: creating a corresponding pdf call document, compressing the created pdf call document and the interface using jar into an SDK compressed package, and outputting the SDK compressed package to the interface applicant.
[0017] According to a second aspect of the present invention, a system for dynamically generating a data service SDK based on a template is provided, the system comprising an SDK generation server, the SDK generation server being used to: construct an SDK template project according to an interface protocol, and obtain the API interface information authorized by the data service platform; generate Java source files of the SDK interface class and the interface parameter class by mapping the obtained API interface information to the created interface parameter template and interface method template; generate corresponding calss files by converting and compiling the Java source files of the SDK interface class and the interface parameter class; create an interface usage jar according to the class file and the SDK template project, and generate and output the SDK according to the created interface usage jar.
[0018] According to a third aspect of the present invention, a computer device is provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the method described in the first aspect of the present invention when executing the program.
[0019] The method, system and device for dynamically generating data service SDK based on templates of the present invention have the following beneficial technical effects:
[0020] 1. Improve the efficiency of SDK development and SDK upgrade. By pre-developing SDK templates to implement the basis of API interface calls, the template engine is used to dynamically generate the upper-level methods of related API interface calls to form a complete personalized SDK. The dynamically generated code is simple and regular, and can be generated by only adding templates and data. Not only is development convenient and efficient, but SDK upgrades can be achieved by simply expanding the SDK template;
[0021] 2. Improve the efficiency of API interface docking, especially for the scenario of batch use of API interfaces. You only need to select multiple applied interfaces. The downloaded SDK already contains the calling methods of these interfaces, and the interface consumers can use them directly, which significantly improves the docking efficiency;
[0022] 3. Improve the ease of use of API interfaces. After the interface consumer downloads the SDK, it introduces the development toolkit. Calling third-party API interfaces is more efficient and convenient than using local methods. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, 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 invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0024] Figure 1 This is an example diagram of a system for dynamically generating a data service SDK based on a template according to an embodiment of the present invention;
[0025] Figure 2 A flowchart of the steps of a method for dynamically generating a data service SDK based on a template according to an embodiment of the present invention;
[0026] Figure 3 This is an example diagram of the execution flow of a method for dynamically generating a data service SDK based on a template according to an embodiment of the present invention;
[0027] Figure 4 A schematic diagram of the structure of the device provided by the present invention. DETAILED DESCRIPTION
[0028] The embodiments of the present invention are described in detail below with reference to the accompanying drawings.
[0029] It should be noted that the following embodiments and features in the embodiments may be combined with each other in the absence of conflict; and, based on the embodiments in the present disclosure, all other embodiments obtained by ordinary technicians in the field without making any creative work are within the scope of protection of the present disclosure.
[0030] It should be noted that various aspects of the embodiments within the scope of the appended claims are described below. It should be apparent that the aspects described herein may be embodied in a wide variety of forms, and any specific structure and / or function described herein is merely illustrative. Based on the present disclosure, it should be understood by those skilled in the art that an aspect described herein may be implemented independently of any other aspect, and two or more of these aspects may be combined in various ways. For example, any number of aspects described herein may be used to implement the device and / or practice the method. In addition, other structures and / or functionalities other than one or more of the aspects described herein may be used to implement this device and / or practice this method.
[0031] Figure 1 FIG. 1 is an example diagram of a system for dynamically generating a data service SDK based on a template according to an embodiment of the present invention. Figure 1 As shown, the system may include an SDK generation server 101, a communication network 102 and / or one or more SDK generation clients 103. Figure 1The example in FIG. 1 generates a client 103 for multiple SDKs.
[0032] The SDK generation server 101 can be any appropriate server for storing information, data, programs and / or any other suitable type of content. In some embodiments, the SDK generation server 101 can perform appropriate functions. For example, in some embodiments, the SDK generation server 101 can be used to dynamically generate a data service SDK based on a template. As an optional example, in some embodiments, the SDK generation server 101 can be used to generate a data service SDK by generating Java source files of SDK interface classes and interface parameter classes. For example, the SDK generation server 101 can be used to: construct an SDK template project according to the interface protocol, obtain the API interface information authorized by the data service platform; generate Java source files of SDK interface classes and interface parameter classes by mapping the obtained API interface information to the created interface parameter template and interface method template; generate corresponding calss files by converting and compiling the Java source files of the SDK interface classes and interface parameter classes; create an interface using jar according to the class file and the SDK template project, and generate and output the SDK according to the created interface using jar.
[0033] As another example, in some embodiments, the SDK generation server 101 may send a method for dynamically generating a data service SDK based on a template to the SDK generation client 103 for user use according to a request of the SDK generation client 103 .
[0034] As an optional example, in some embodiments, the SDK generation client 103 is used to provide a visual SDK generation interface, which is used to receive a user's selection input operation to dynamically generate a data service SDK based on a template, and to, in response to the selection input operation, obtain from the SDK generation server 101 an SDK generation interface corresponding to the option selected by the selection input operation and display the SDK generation interface, wherein the SDK generation interface displays at least information on the data service SDK dynamically generated based on the template and operation options for the information on the data service SDK dynamically generated based on the template.
[0035] In some embodiments, the communication network 102 can be any suitable combination of one or more wired and / or wireless networks. For example, the communication network 102 can include any one or more of the following: the Internet, an intranet, a wide area network (WAN), a local area network (LAN), a wireless network, a digital subscriber line (DSL) network, a frame relay network, an asynchronous transfer mode (ATM) network, a virtual private network (VPN), and / or any other suitable communication network. The SDK generation client 103 can be connected to the communication network 102 via one or more communication links (e.g., communication link 104), and the communication network 102 can be linked to the SDK generation service end 101 via one or more communication links (e.g., communication link 105). The communication link can be any communication link suitable for transmitting data between the SDK generation client 103 and the SDK generation service end 101, such as a network link, a dial-up link, a wireless link, a hard-wired link, any other suitable communication link, or any suitable combination of such links.
[0036] SDK generation client 103 may include any one or more clients that present an interface related to dynamically generating a data service SDK based on a template in an appropriate form for use and operation by a user. In some embodiments, SDK generation client 103 may include any suitable type of device. For example, in some embodiments, SDK generation client 103 may include a mobile device, a tablet computer, a laptop computer, a desktop computer, and / or any other suitable type of client device.
[0037] Although the SDK generation server 101 is illustrated as one device, in some embodiments, any suitable number of devices may be used to perform the functions performed by the SDK generation server 101. For example, in some embodiments, multiple devices may be used to implement the functions performed by the SDK generation server 101. Alternatively, a cloud service may be used to implement the functions of the SDK generation server 101.
[0038] Based on the above system, an embodiment of the present application provides a method for dynamically generating a data service SDK based on a template, which is described below through the following embodiments.
[0039] Figure 2 This is a flowchart of a method for dynamically generating a data service SDK based on a template according to an embodiment of the present invention. The method for dynamically generating a data service SDK based on a template in this embodiment can be executed on an SDK generation server. The method for dynamically generating a data service SDK based on a template includes the following steps:
[0040] Step S201: construct an SDK template project according to the interface protocol, and obtain the API interface information authorized by the data service platform.
[0041] As an optional example, in this embodiment, by matching the calling method, configuration and dependency for the interface protocol, a corresponding SDK template project is constructed. In this embodiment, the SDK template project serves as the minimum client for accessing the API gateway interface. In actual applications, in addition to providing basic calling methods, it also provides a method for accessing the API gateway to query the authentication code. This method is automatically called when accessing the API gateway interface through the SDK, and the authentication code is dynamically obtained based on the local timestamp and the agreed public key value as parameters, which is used for gateway authentication when accessing the API interface remotely. In this embodiment, SDK is a software development kit that provides the resources required for development and facilitates developers to build applications using APIs and their functions.
[0042] In this embodiment, the API interface information includes the interface call URL, request method, media type, interface parameter structure and authorization token. After obtaining the interface call URL, request method and media type, the basic call method can be assigned to the generated SDK interface according to the request method. The interface call URL is the access path of the API interface on the gateway. The interface call URL and media type are passed as fixed parameters to the basic call method; the interface information also includes an interface parameter structure, which is used to guide the interface consumer to dynamically pass in parameter values and encapsulate the return results, and the authorization token provided by the interface information is used for internal authentication of accessing the API interface.
[0043] Step S202: Generate Java source files of the SDK interface class and interface parameter class by mapping the acquired API interface information to the created interface parameter template and interface method template.
[0044] As an optional example, in this embodiment, an interface parameter template and an interface method template are created, and the Java source files of the SDK interface class and the interface parameter class are generated by mapping the acquired API interface information to the created interface parameter template and the interface method template. For example, in this embodiment, an interface parameter template and an interface method template are created respectively by using the FreeMarker template language, and the API interface information is mapped to the created interface parameter template and the interface method template respectively by using the template engine tool, and the Java source files of the SDK interface class and the interface parameter class are generated.
[0045] For example, in this embodiment, the interface parameter template and the interface method template are defined respectively by the FreeMarker template language, and then the template engine tool is used to map the API interface information to the interface parameter template and the interface method template respectively, and the Java source files of the SDK interface class and the interface parameter class are generated. In actual applications, the SDK interface class and its methods are named by the last two levels of the API interface access path respectively. The interface consumer calls the SDK interface according to the API path, enters the corresponding basic calling method, and completes the access to the API gateway interface. In this embodiment, FreeMarker is a template engine, which is a general tool for generating output texts such as configuration files and source code based on templates and data to be changed.
[0046] Step S203: converting and compiling the Java source files of the SDK interface class and the interface parameter class to generate corresponding calss files.
[0047] As an optional example, in this embodiment, the Java source files of the SDK interface class and the interface parameter class are converted into file objects, the file objects to be compiled are converted into compilation units through the file manager, a compilation task is constructed for the compilation unit obtained by the conversion, and the JavaCompiler compilation tool is used to execute the compilation task to obtain the corresponding class file. In this embodiment, JavaCompiler is a Java dynamic compiler interface for compiling Java source files into class files. The class file of this embodiment is a specific binary file of the Java virtual machine.
[0048] Step S204: Create an interface using jar according to the class file and the SDK template project, and generate and output the SDK according to the created interface using jar.
[0049] As an optional example, in this embodiment, a target file corresponding to the interface using jar is created, and the compiled class file and the SDK template project are written into the created target file by using JarOutputStream file output stream in turn to create the interface using jar. It should be noted that the SDK template project in this embodiment is a basic jar. JarOutputStream is a jar file output stream that can package multiple files into a jar file.
[0050] After creating the interface usage jar, this embodiment creates a corresponding pdf call document, compresses the created pdf call document and the interface usage jar into an SDK compressed package, and outputs the SDK compressed package to the interface applicant. In this embodiment, jar is a common archive format for Java, which can be used to package Java libraries, i.e., dependencies, reused components, or Java applications.
[0051] Figure 3 FIG. 1 is an example diagram of the execution flow of a method for dynamically generating a data service SDK based on a template according to an embodiment of the present invention. Figure 3 As shown, first create an SDK template project as the minimum client to access the API gateway interface. When the interface applicant sends a request to download the SDK, the data service platform receives the request and first obtains the relevant API interface information, maps it to the FreeMarker template that logically depends on the basic jar through the template engine to generate a Java source file; then converts these Java source files into compilation units, and uses the Java compilation tool to compile them into class files; then merge the compiled class files and the basic jar into the interface usage jar; then create a pdf call document, and compress it together with the interface usage jar into a zip format SDK; finally, download and output the compressed SDK. After receiving the SDK, the interface applicant decompresses it and introduces it into the development toolkit, thereby realizing efficient calling of third-party API interfaces, which is as simple as using local method calls.
[0052] The present invention applies the layered concept and divides the universal code and personalized code for generating SDK into two layers. The universal code is used as the underlying logic for processing API interface calls as a dependency, and the personalized code is the upper-level method of interface calls as the API interface changes. The SDK template project is introduced, and the template project provides basic calling methods for different interface protocols, and pre-encapsulates the complex logic and details of the interface call in the template. The SDK template project serves as the basis for generating SDK. The template engine is used to define the upper-level method of interface calls through the FreeMarker template. When generating SDK, it is only necessary to obtain relevant API interface information, and the rest is processed through the pipeline of generating source code, compiling and packaging through the template engine.
[0053] In practical applications, the method and system of the present invention for dynamically generating a data service SDK based on a template has the following beneficial effects:
[0054] 1. Improve the efficiency of SDK development and SDK upgrade. By pre-developing SDK templates to implement the basis of API interface calls, the template engine is used to dynamically generate the upper-level methods of related API interface calls to form a complete personalized SDK. The dynamically generated code is simple and regular, and can be generated by only adding templates and data. Not only is development convenient and efficient, but SDK upgrades can be achieved by simply expanding the SDK template;
[0055] 2. Improve the efficiency of API interface docking, especially for the scenario of batch use of API interfaces. You only need to select multiple applied interfaces. The downloaded SDK already contains the calling methods of these interfaces, and the interface consumers can use them directly, which significantly improves the docking efficiency;
[0056] 3. Improve the ease of use of API interfaces. After the interface consumer downloads the SDK, it introduces the development toolkit. Calling third-party API interfaces is more efficient and convenient than using local methods.
[0057] like Figure 4 As shown, the present invention also provides a device, including a processor 310, a communication interface 320, a memory 330 for storing a computer program executable by the processor, and a communication bus 340. The processor 310, the communication interface 320, and the memory 330 communicate with each other through the communication bus 340. The processor 310 implements the above-mentioned method of dynamically generating a data service SDK based on a template by running an executable computer program.
[0058] Among them, the computer program in the memory 330 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on this understanding, the technical solution of the present application can be essentially or partly embodied in the form of a software product that contributes to the prior art, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the various embodiments 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.
[0059] The system embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, i.e., they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected based on actual needs to achieve the purpose of the solution of this embodiment. Those of ordinary skill in the art may understand and implement it without creative effort.
[0060] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods of each embodiment or some parts of the embodiment.
[0061] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any changes or substitutions that can be easily thought of by a person skilled in the art within the technical scope disclosed by the present invention should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.
Claims
1. A method for dynamically generating a data service SDK based on a template, characterized in that: The method comprises: Build an SDK template project according to the interface protocol to obtain the API interface information authorized by the data service platform; By mapping the obtained API interface information to the created interface parameter template and interface method template, Java source files of the SDK interface class and interface parameter class are generated; Generate the corresponding calss files by converting and compiling the Java source files of SDK interface class and interface parameter class; Create an interface using jar according to the class file and SDK template project, and generate and output SDK using jar according to the created interface.
2. The method for dynamically generating a data service SDK based on a template according to claim 1, characterized in that: Building an SDK template project according to the interface protocol includes: building a corresponding SDK template project by matching calling methods, configurations, and dependencies for the interface protocol.
3. The method for dynamically generating a data service SDK based on a template according to claim 1, characterized in that: API interface information includes interface call URL, request method, media type, interface parameter structure and authorization token.
4. The method for dynamically generating a data service SDK based on a template according to claim 1, characterized in that: By mapping the acquired API interface information to the created interface parameter template and interface method template, Java source files of the SDK interface class and interface parameter class are generated, including: creating an interface parameter template and an interface method template, and by mapping the acquired API interface information to the created interface parameter template and interface method template, Java source files of the SDK interface class and interface parameter class are generated.
5. The method for dynamically generating a data service SDK based on a template according to claim 4, characterized in that: By mapping the acquired API interface information to the created interface parameter template and interface method template, Java source files of the SDK interface class and interface parameter class are generated, including: creating interface parameter templates and interface method templates respectively through the FreeMarker template language, mapping the API interface information to the created interface parameter template and interface method template respectively through the template engine tool, and generating Java source files of the SDK interface class and interface parameter class.
6. The method for dynamically generating a data service SDK based on a template according to claim 1, characterized in that: The Java source files of the SDK interface class and the interface parameter class are converted and compiled to generate corresponding calss files, including: converting the Java source files of the SDK interface class and the interface parameter class into file objects, converting the file objects to be compiled into compilation units through the file manager, building compilation tasks for the compilation units obtained by the conversion, and using the JavaCompiler compilation tool to execute the compilation tasks to obtain the corresponding class files.
7. The method for dynamically generating a data service SDK based on a template according to claim 1, characterized in that: Create an interface using jar according to the class file and SDK template project, including: creating a target file corresponding to the interface using jar, writing the compiled class file and the built SDK template project into the created target file by using the JarOutputStream file output stream in sequence, and creating an interface using jar.
8. The method for dynamically generating a data service SDK based on a template according to claim 1, characterized in that: Generate and output SDK using jar according to the created interface, including: create corresponding pdf call document, compress the created pdf call document and interface into SDK compressed package using jar, and output the SDK compressed package to the interface applicant.
9. A system for dynamically generating data service SDK based on templates, characterized in that: The system includes an SDK generation server, which is used to: build an SDK template project according to the interface protocol to obtain API interface information authorized by the data service platform; generate Java source files of SDK interface class and interface parameter class by mapping the obtained API interface information to the created interface parameter template and interface method template; generate corresponding calss files by converting and compiling the Java source files of SDK interface class and interface parameter class; create an interface usage jar according to the class file and the SDK template project, and generate and output SDK according to the created interface usage jar.
10. A computer device, characterized in that: The computer device comprises a memory, a processor and a computer program stored in the memory and executable on the processor, and the processor implements the steps of the method according to any one of claims 1 to 8 when executing the program.
Citation Information
Patent Citations
Service construction method and device, loading method and device, electronic equipment and storage medium
CN109814943A
SDK generation method, device and equipment and readable storage medium
CN112380145A
API platform implementation method, device and equipment, and storage medium
CN112612452A
SDK generation and self-upgrading method and device, readable medium and equipment
CN113407165A
Software development kit (SDK) generation method and device and electronic equipment
CN113590098A
