A micro-service gateway generating API interface, a generating method and related devices
By introducing the engine layer and routing layer of the microservice gateway, the configuration of API interfaces is automated, which solves the problem of the traditional API gateway having limited functionality, improves the development efficiency and security of API interfaces, and reduces the development difficulty and cycle.
Patent Information
- Application Number
- CN202211255249.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-10-13
- Publication Date
- 2025-12-30
- Estimated Expiration
- 2042-10-13
AI Technical Summary
Traditional API gateways have limited functionality, lack documentation and automated testing support, resulting in low API development efficiency, long development cycles, and developers having to spend a lot of time on non-core tasks.
A microservice gateway is provided, comprising an engine layer and a routing layer. The engine layer stores a custom framework, provides an interface engine, and implements data security verification, API test cases, and documentation generation. The routing layer configures API interface routing information and may optionally include a remote call protocol and a conversion layer for version conversion.
To automate API configuration, improve development efficiency, shorten development cycle, reduce development difficulty, minimize security issues, and automatically generate documentation and test cases.
Smart Images

Figure CN115633074B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of network security, and in particular to a microservice gateway for generating API interfaces, a method for generating API interfaces, a storage medium, and an electronic device. Background Technology
[0002] As business architecture evolves and becomes increasingly complex, it is gradually broken down into various microservices. To provide a consistent API access method, an API gateway is needed. However, traditional API gateways focus primarily on forwarding the API itself, offering limited functionality. Adding API implementations becomes complex and can easily introduce security issues. They lack documentation and automated testing support, resulting in lengthy API development and deployment cycles, requiring developers to dedicate significant time and effort to non-API development tasks.
[0003] Therefore, how to improve the development efficiency of API interfaces that include multiple functions is a technical problem that urgently needs to be solved by those skilled in the art. Summary of the Invention
[0004] The purpose of this application is to provide a microservice gateway for generating API interfaces, a method for generating API interfaces, a storage medium, and an electronic device, which can realize automated configuration of the API interface's functional engine and improve the development efficiency of API interfaces.
[0005] To address the aforementioned technical problems, this application provides a microservice gateway for generating API interfaces, comprising:
[0006] The engine layer stores the custom framework of the API interface and provides the interface engine; the interface engine includes at least one of the following for implementing the API interface: data security verification, API test case testing process, and API documentation generation.
[0007] The routing layer is used to configure the routing information for API interfaces and obtain the API interfaces.
[0008] Optionally, the routing layer includes a remote invocation protocol and is also used to forward the API interface to the corresponding API service using the remote invocation protocol.
[0009] Optional, also includes:
[0010] The conversion layer is used to perform version conversion on the API interface, or to convert external API interface requests into function calls corresponding to internal API interfaces.
[0011] Optionally, the conversion layer is also used to encapsulate the backend configuration and / or backend services corresponding to the API operations contained in the API interface.
[0012] This application also provides a method for generating API interfaces, based on the microservice gateway described above, the generation method comprising:
[0013] Receive API generation requests;
[0014] Confirm the engine parameters in the API generation request and determine the routing information;
[0015] Call the custom framework in the engine layer, and call the interface engine in the engine layer according to the engine parameters to configure the API engine corresponding to the custom framework;
[0016] The routing layer is invoked to configure the routing information of the API engine, thereby obtaining the API interface.
[0017] Optionally, the routing layer is invoked to configure the routing information of the API engine, and the API interfaces obtained include:
[0018] If the API generation request contains target routing information, the routing information of the API interface shall be configured using the target routing information;
[0019] If the API generation request does not contain target routing information, the routing information of the API interface is configured using the default routing information in the routing layer.
[0020] Optionally, after calling the routing layer to configure the routing information of the API engine and obtaining the API interface, the following steps are also included:
[0021] The API interface is forwarded to the corresponding API service using a remote procedure call protocol.
[0022] Optionally, upon receiving an interface upgrade request, the following may also be included:
[0023] The API interface can be version converted using a conversion layer, or external API interface requests can be converted into function calls corresponding to internal API interfaces.
[0024] This application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the method described above.
[0025] This application also provides an electronic device, including a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the method described above when it invokes the computer program in the memory.
[0026] This application provides a microservice gateway for generating API interfaces, comprising: an engine layer for storing a custom framework for the API interfaces and providing an interface engine; the interface engine includes at least one of data security verification, API test case testing process, and API documentation generation for implementing the API interfaces; and a routing layer for configuring routing information for the API interfaces to obtain the API interfaces.
[0027] The microservice gateway provided in this application has a custom framework configured in the engine layer, as well as an interface engine for configuring API functions and business implementations. When it is necessary to implement functions other than API interface forwarding, the interface engine can be used directly for configuration, without developers having to write additional code for other API interface functions. It can automatically generate API interfaces containing multiple API functions and business implementations, improve the development efficiency of API interfaces, shorten the development cycle of API interfaces, and reduce the development difficulty of multiple functional API interfaces.
[0028] This application also provides a method for generating an API interface, a storage medium, and an electronic device, which have the aforementioned beneficial effects, and will not be elaborated further here. Attached Figure Description
[0029] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of this application. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.
[0030] Figure 1 This is a schematic diagram of the structure of a microservice gateway for generating API interfaces provided in an embodiment of this application;
[0031] Figure 2 This is a schematic diagram of another microservice gateway for generating API interfaces provided in an embodiment of this application.
[0032] Figure 3 A flowchart illustrating an API interface generation method provided in this application embodiment:
[0033] Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0034] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0035] See Figure 1 , Figure 1 This is a schematic diagram of the structure of a microservice gateway for generating API interfaces provided in an embodiment of this application. The microservice gateway includes:
[0036] The engine layer stores the custom framework for the API interfaces and provides the interface engine.
[0037] The routing layer is used to configure the routing information for API interfaces and obtain the API interfaces.
[0038] A microservice gateway is an intermediary device that provides API entry points for microservices, sitting between the client and the server. All external requests pass through the microservice gateway first, and the client only needs to interact with the gateway. For the client, only the gateway address is needed; there's no need to remember the network addresses of each microservice. The microservice gateway provided in this embodiment mainly includes an engine layer and a routing layer for generating API interfaces. The engine layer can include HTTP server parsing and RESTful schema parsing, i.e., parsing HTTP requests into the format of custom API interfaces, and similarly, providing access APIs for REST servers. The engine layer can use an IDL framework, which is a framework for automatically defining code. It can declare an interface, and the engine translates the language into documentation, etc. Of course, the engine layer can also use other frameworks to implement the basic definition of the API interface. Furthermore, the engine layer is also responsible for storing the custom framework of the API interface. This custom framework can be automatically configured by those skilled in the art; any framework structure used to implement the API interface is acceptable and is not specifically limited here. A schema is a standard for describing XML documents. In other words, the engine layer can receive HTTP requests or parse XML documents to obtain the format of the custom API interface or the functional instructions required by the API interface.
[0039] The engine layer also includes an interface engine, used to implement the relevant functions and business logic of the API interfaces. This includes, but is not limited to, API interface data security verification, API test case testing, and API documentation generation. It may also include API implementations for introducing and describing the API interfaces. Once the interface engine configuration is complete, the corresponding functions in the interface engine can be called to complete the API interface configuration as needed. It's important to note that the interface engine implementation typically needs to be completed after the custom framework configuration is finished; for example, it can be automatically completed by the interface engine after the schema definition is finalized. API interface data security verification refers to the verification of API requests, including but not limited to permission verification and parameter verification. API test cases refer to the test application process of the API interface, used to indicate the stability and security of the current API interface's application implementation. API documentation generation is used to generate relevant functional descriptions and other information for the current API interface, facilitating rapid application by the client.
[0040] It should also be noted that the interface engine can also be used to implement other API functions and business implementations. As long as people in this field write the corresponding API functions and business implementations in advance based on the custom framework and language, and store them in the engine layer in the form of an interface engine, they can directly use the interface engine to configure them during the API interface generation process.
[0041] This document does not limit the definition of how to implement the API engine. One feasible implementation method is to define it using a standardized schema. For example, standardized API interfaces and API implementations can be automatically generated based on the standardized schema, reducing development costs. Furthermore, API data security verification can be automatically performed, reducing the number of security issues caused by developer negligence. API documentation and API test cases can also be automatically generated, facilitating API deployment.
[0042] The routing layer is primarily used to configure routing information for API interfaces and obtain the API interfaces. The configuration process can be divided into default routes and custom routes. If the received HTTP request does not contain a custom route, the API interface will use the default route by default; otherwise, it will use the custom route from the HTTP request. After configuring the routing information, the routing layer can route the API interface to the appropriate plugin for processing, thereby implementing the corresponding API business logic.
[0043] In other embodiments, the routing layer can also be used to implement filtering, that is, to filter API requests for which the corresponding permissions are not met, such as API requests from unauthorized users, and generate corresponding log information. This API request refers to the request used to control the routing layer to route the API interface to the appropriate plugin.
[0044] The microservice gateway provided in this application embodiment is configured with a custom framework and an interface engine for configuring API functions and business implementations in the engine layer. When it is necessary to implement functions other than API interface forwarding, the interface engine can be used directly for configuration. Developers do not need to write additional code for other API interface functions for the API interface. It can automatically generate API interfaces containing multiple API functions and business implementations, improve the development efficiency of API interfaces, shorten the development cycle of API interfaces, and reduce the development difficulty of multiple functional API interfaces.
[0045] Building upon the above embodiments, the routing layer may further include a remote procedure call (RPC) protocol for forwarding the API interface to the corresponding API service. The specific RPC protocol used is not limited here; it is a method of accessing other servers based on the TCP / IP protocol. It can be seen that the routing layer is used to implement API forwarding, converting the API interface to the corresponding service or microservice. The specific service is not limited here and may include, but is not limited to, configuration centers, status centers, VPN services, etc.
[0046] Based on the above embodiments, as a preferred execution method, the microservice gateway may further include a conversion layer for version conversion of API interfaces, or for converting external API interface requests into function calls corresponding to internal API interfaces. When upgrading API interfaces, the conversion layer can be used directly to logically update the API interfaces, enabling updates from older versions to newer versions, or from lower versions to higher versions. Upon receiving an external API request, the conversion layer can convert the external API request into an internal function call for processing.
[0047] See Figure 2 , Figure 2 This is a schematic diagram of another microservice gateway for generating API interfaces provided in this application embodiment. As a preferred execution method, a conversion layer can be used to encapsulate the backend configuration and / or backend services corresponding to the API operation within the API interface. That is, the API logic is encapsulated in the conversion layer. If an API operation involves multiple backend configurations or backend services, the multiple backend API data can be re-encapsulated and provided externally. The so-called API logic refers to the API implementation, including business logic implementations such as configuration modification and status reading, all of which can be encapsulated by the conversion layer and provided externally. At the same time, the conversion layer can also be used to receive the response results returned by various services and return them to the engine layer.
[0048] Depend on Figure 2As can be seen, this microservice gateway sequentially comprises an engine layer, a routing layer, and a transformation layer, capable of generating and applying API interfaces, thus achieving more complete gateway functionality. Compared to the previous embodiment, the transformation layer provided in this embodiment directly enables the microservice gateway to be used for interaction between servers and clients, achieving efficient application of API interfaces.
[0049] Based on the above embodiments, if the business objects that the routing layer needs to forward are relatively complex, plugins can be configured in the conversion layer to extend the interface and better connect with the business objects, ensuring that the API interface can be successfully forwarded to the corresponding business.
[0050] See Figure 3 , Figure 3 This is a flowchart illustrating an API interface generation method provided in an embodiment of this application. This application also provides an API interface generation method based on the microservice gateway described above. The generation method described below can be referenced and compared with the microservice gateway described above. The generation method includes:
[0051] S301: Receive API generation request;
[0052] This step aims to receive an API generation request. No specific limitations are made regarding how the API generation request is received, nor are there any specific limitations on its content or format. In one feasible implementation, the API generation request can be an HTTP request, i.e., received via an HTTP server to generate the API interface.
[0053] Furthermore, the API generation request can include the business functions corresponding to the API interface to be generated. That is, before generating the API interface, the business functions contained in the API interface can be set through the API generation request using engine parameters.
[0054] S302: Confirm the engine parameters in the API generation request and determine the routing information;
[0055] This step aims to determine the engine parameters and the routing information for the API interface. The engine parameters are used to invoke the business functions of the API interfaces in the microservice gateway's interface engine. The specific content of the engine parameters is not limited here; they can be codes or numbers of various business functions within the interface engine, etc.
[0056] Routing information is used to configure API routing. There are no restrictions on how the routing information is determined. One possible approach is to use the target routing information to configure the API routing if the API request contains target routing information; otherwise, the default routing information from the routing layer is used.
[0057] S303: Call the custom framework in the engine layer, and call the interface engine in the engine layer according to the engine parameters to configure the API engine corresponding to the custom framework;
[0058] S304: Call the routing layer to configure the routing information of the API engine and obtain the API interface.
[0059] In steps S303 and S304, the engine parameters and routing information determined above need to be applied to the custom framework. First, configure the API engine according to the engine parameters, and then configure the routing information of the API interface to obtain the API interface.
[0060] After step S304, the API interface can be directly forwarded to the corresponding API service using the remote call protocol in the routing layer to realize the application of the API interface.
[0061] Furthermore, upon receiving an API request, permission verification can be performed on the request to achieve authentication and authorization. This allows for filtering of unauthorized API requests at the routing layer. This permission verification can include confirming whether the user or request initiator has access control permissions for the API interface, and can also include other permission verifications, which will not be listed here.
[0062] This application provides an API interface generation method. After receiving an API generation request, the method determines the engine parameters and routing information, and configures the API based on the interface engine in the custom framework and engine layer. This can generate API interfaces containing various API implementations, such as API interface data security verification, automatic generation of API documentation and test cases, eliminating the need for developers to write programs in real time, reducing development manpower and time costs, and facilitating API release.
[0063] Based on the above embodiments, as a preferred embodiment, upon receiving an interface upgrade request, a conversion layer is used to perform version conversion on the API interface, or the external API interface request is converted into a function call corresponding to the internal API interface. This interface upgrade request is used for API interface version upgrades or API interface feature upgrades.
[0064] When an interface upgrade request is received, this embodiment can directly use the conversion layer to perform version conversion without requiring users to manually rewrite the API interface code. This enables automated API interface upgrades and reduces the burden on developers for subsequent API interface maintenance.
[0065] This application also provides a computer-readable storage medium storing a computer program thereon, which, when executed, can implement the steps of the methods provided in the above embodiments. The storage medium may include various media capable of storing program code, such as a USB flash drive, a portable hard drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.
[0066] This application also provides an electronic device that may include a memory and a processor. The memory stores a computer program, and when the processor invokes the computer program in the memory, it can implement the steps of the method provided in the above embodiments. Of course, the electronic device may also include various network interfaces, power supplies, and other components. Please see [link to relevant documentation]. Figure 4 , Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. The electronic device in this embodiment may include: a processor 2101 and a memory 2102.
[0067] Optionally, the electronic device may also include a communication interface 2103, an input unit 2104, a display 2105, and a communication bus 2106.
[0068] The processor 2101, memory 2102, communication interface 2103, input unit 2104, and display 2105 all communicate with each other through the communication bus 2106.
[0069] In this embodiment of the application, the processor 2101 may be a central processing unit (CPU), an application-specific integrated circuit, a digital signal processor, an off-the-shelf programmable gate array, or other programmable logic devices.
[0070] The processor can call programs stored in memory 2102. Specifically, the processor can execute the operations performed by the electronic device in the above embodiments.
[0071] The memory 2102 is used to store one or more programs, which may include program code, including computer operation instructions. In this embodiment, the memory stores at least a program for implementing the following functions:
[0072] Receive API generation requests;
[0073] Confirm the engine parameters in the API generation request and determine the routing information;
[0074] Call the custom framework in the engine layer, and call the interface engine in the engine layer according to the engine parameters to configure the API engine corresponding to the custom framework;
[0075] The routing layer is invoked to configure the routing information of the API engine, thereby obtaining the API interface.
[0076] In one possible implementation, the memory 2102 may include a program storage area and a data storage area, wherein the program storage area may store the operating system and applications required for at least one function; and the data storage area may store data created during the use of the computer.
[0077] In addition, memory 2102 may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device or other volatile solid-state storage device.
[0078] The communication interface 2103 can be an interface for a communication module, such as the interface for a GSM module.
[0079] This application may also include a display 2105 and an input unit 2104, etc.
[0080] Figure 4 The structure of the electronic device shown does not constitute a limitation on the electronic device in the embodiments of this application. In practical applications, the electronic device may include more than [other components]. Figure 4 More or fewer components as shown, or combinations of certain components.
[0081] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. As the system provided in the embodiments corresponds to the method provided in the embodiments, the description is relatively simple; relevant parts can be found in the method section.
[0082] This document uses specific examples to illustrate the principles and implementation methods of this application. The descriptions of the embodiments above are only for the purpose of helping to understand the method and core ideas of this application. It should be noted that those skilled in the art can make several improvements and modifications to this application without departing from the principles of this application, and these improvements and modifications also fall within the protection scope of the claims of this application.
[0083] It should also be noted that, in this specification, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
Claims
1. A microservice gateway generating an API interface, characterized in that, The method comprises the following steps: An engine layer is configured to store a custom framework of the API interface and provide an interface engine; The interface engine is configured to implement at least one of data security verification, API test case testing process and API document generation of the API interface, and complete configuration of the API interface according to generation requirements of the API interface; A routing layer is configured to configure routing information of the API interface, obtain the API interface, filter API requests without corresponding permissions and generate corresponding log information; and the generation requirements of the API interface include API functions required by the API interface; A conversion layer is configured to perform version conversion on the API interface or convert external API interface requests into function calls corresponding to the internal API interface; and the conversion layer is further configured to encapsulate backend configurations and / or backend services corresponding to API operations included in the API interface, receive response results returned by each business and return the response results to the engine layer.
2. The microservice gateway of claim 1, wherein, The routing layer includes a remote invocation protocol, and is further configured to forward the API interface to corresponding API businesses by using the remote invocation protocol.
3. A method of generating an API interface, characterized by, The microservice gateway according to claim 1 or 2, the generation method comprising: receiving an API generation request; confirming engine parameters in the API generation request and determining routing information; calling a custom framework in the engine layer, calling an interface engine in the engine layer according to the engine parameters and configuring an API engine corresponding to the custom framework; calling a routing layer to configure routing information of the API engine and obtaining an API interface.
4. The generation method of claim 3, wherein, The method of calling the routing layer to configure the routing information of the API engine and obtaining the API interface comprises: if the API generation request includes target routing information, configuring the routing information of the API interface by using the target routing information; if the API generation request does not include target routing information, configuring the routing information of the API interface by using default routing information in the routing layer.
5. The method of generating of claim 3, wherein, After the method of calling the routing layer to configure the routing information of the API engine and obtaining the API interface, the method further comprises: forwarding the API interface to corresponding API businesses by using a remote invocation protocol.
6. The method of generating of claim 3, wherein, When the interface upgrade request is received, the method further comprises: performing version conversion on the API interface by using a conversion layer, or converting external API interface requests into function calls corresponding to the internal API interface.
7. A computer readable storage medium having stored thereon a computer program, characterized in that The computer program is executed by a processor to implement the steps of the method according to any one of claims 3-6.
8. An electronic device, comprising: The computer program is stored in a memory and executed by a processor to implement the steps of the method according to any one of claims 3-6.
Citation Information
Patent Citations
Method for unified management and release of security API interface in ERP system
CN112612461A
Gateway API development method and device
CN114579085A