A method for microservice-based API gateway configuration and forwarding
By creating relationships between services, APIs, and products in the API gateway, and binding plugin groups and plugin instances, the challenges of managing and operating the API gateway in a microservice architecture are solved. This enables flexible update and customization strategies, reduces operating costs, and improves system security and reliability.
Patent Information
- Application Number
- CN202311556488.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-11-21
- Publication Date
- 2026-11-20
- Estimated Expiration
- 2043-11-21
AI Technical Summary
Existing API gateways are difficult to manage in a microservice architecture, cannot hot-update configuration files, and developers cannot dynamically publish plugins. Furthermore, each microservice needs to implement security controls independently, which increases system complexity and operational costs.
By creating relationships between services, APIs, and products, binding plugin groups and plugin instances, it supports hot updates and hot releases of plugins, dynamically expands API gateway functionality, achieves separation of business and technology, and enables customized access strategies through plugin combinations.
It enables flexible updates and management of the API gateway, reduces operation and maintenance costs, supports distributed API integration and large-scale access, improves system security and reliability, reduces service exposure, and adapts to customized processes for different needs.
Smart Images

Figure CN117527586B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of API gateway technology, and in particular relates to a method for configuring and forwarding API gateways based on microservices. Background Technology
[0002] Today, most modern applications are built using APIs. An API is a software interface that enables communication between two applications and allows products and services to interact in the form of requests and responses.
[0003] As APIs become more prevalent and distributed across microservice architectures, additional infrastructure is needed to ensure scalability and security. The concept of an API gateway is based on microservice architecture, serving as a unified request entry point, routing requests, and extracting logic unrelated to business logic, completely separating it from the core business logic.
[0004] Currently available API gateways all offer unified authentication, authorization, and request filtering and forwarding capabilities. However, in practical use, they suffer from several issues: inability to manage APIs uniformly, configuration based on configuration files hindering hot updates, developers cannot dynamically publish plugins, and individual filter chains cannot be configured for each API. Furthermore, API security controls must be implemented by each microservice, increasing their complexity and violating microservice design principles. Single Responsibility Principle .
[0005] Therefore, how to make API gateway updates and management more convenient while reducing API gateway operation and maintenance costs has become an urgent problem to be solved. Summary of the Invention
[0006] To address the shortcomings of the existing technologies, this invention provides a method for configuring and forwarding API gateways based on microservices, which can facilitate the updating and management of API gateways while reducing the operation and maintenance costs of API gateways.
[0007] To solve the above-mentioned technical problems, the present invention adopts the following technical solution: A method for configuring and forwarding API gateways based on microservices includes the following steps: S1. The backend creates a service and configures the service information; the service information includes the service name, service code, version number, and whether to find the service address through service discovery.
[0008] S2, API for creating services; S3. Create a product for external exposure and configure product information; the product information includes product name, product code, and product routing policy.
[0009] S4. Bind products and services, establish the relationship between products and services, and generate operations under the product in batches through the API of the service bound to the product. One operation corresponds to one API request of the service. S5. Create plugin groups and plugin instances under plugin groups according to requirements; in practice, the plugin groups created are personalized plugin groups.
[0010] S6. Create the relationship between operations and plugin groups, and specify the order of plugin groups under the same operation; S7. After receiving the user's operation, activate the service API request corresponding to the operation and execute the functions of the plugin group associated with the operation.
[0011] Compared with the prior art, the present invention has the following advantages: 1. Using this method, after creating services, APIs, and products, the relationship between products and services is established. Operations under a product are then generated in batches through the APIs of the services bound to that product. One product can correspond to multiple services. This exposes a single product externally, but technically it is implemented by multiple microservices, ensuring separation of business and technology and a clearer hierarchy. One operation represents an API request for one service, and the relative path of the API request is the relative path of the API interface. Thus, when a user's operation request arrives, the routing strategy in the product information can locate the specific product, and combined with the request URL, the complete access path to the specific API can be determined. By importing APIs and creating products to associate them, different APIs are bound to products, facilitating the creation of different access strategies for users.
[0012] Next, plugin groups and plugin instances within those groups can be created based on specific needs. The relationship between operations and plugin groups can then be established, specifying the order of plugin groups under the same operation. Upon receiving a user's operation, the corresponding service API request can be activated, and the functionality of the associated plugin group can be executed. This allows for the development of a series of plugins to form a plugin chain, binding plugins or plugin groups according to API usage scenarios. Plugin logic is executed during API access to fulfill customized requirements. Using an API gateway supports dynamic expansion without requiring deployment or modification of load balancers. When users need to integrate functions from different products or services and call capabilities provided by different services, the API gateway can complete interface assembly without being aware of edge services, reducing service exposure and increasing system security.
[0013] This approach is suitable for distributed API integration and large-scale API access while ensuring low latency. Plugin configuration allows for customization of processes and requirements; dynamic API expansion eliminates the need to deploy and modify load balancers, reducing operational costs and increasing system uptime.
[0014] 2. In addition, this method supports hot deployment of products and services. If a new product is deployed or the routing strategy is modified, there is no need to restart the system. After detecting changes in the product, the routing strategy can be loaded into memory, and route assertions can be performed when a request arrives. This method supports hot updates of plugins. If it is necessary to modify the associated plugins or plugin configurations, the changes will take effect immediately without restarting the system.
[0015] In summary, this method makes it easier to update and manage API gateways, while reducing their operational costs.
[0016] Preferably, after S6, the system further includes S61, which creates policies for each operation and assigns policies to each user's account as needed; the policies include allowing or disallowing. In S7, after receiving a user's operation, it also determines whether the operation is allowed based on the policy corresponding to the operation for that account. If allowed, it activates the service API request corresponding to the operation and executes the functions of the plugin group associated with the operation.
[0017] This setup, by controlling user subscription access restrictions, can be effectively integrated with the enterprise's operational strategies. Furthermore, it implements identity authentication and permission verification, improving the security of the distributed system and effectively avoiding the performance overhead caused by independent authentication for each service.
[0018] Preferably, in S5, the created plugin group is a personalized plugin group; in S6, when creating the relationship between the operation and the plugin group, the plugin group is a personalized plugin group.
[0019] In this way, personalized plugin groups can be created to meet the specific needs of each user, making it easy to implement customized functions for each user.
[0020] Preferably, in S6, when creating the relationship between an operation and a plugin group, an operation can be associated with multiple plugin groups, and a plugin group can also be associated with multiple different operations.
[0021] This setup makes full use of the created plugin groups while ensuring the functionality and effectiveness of each operation.
[0022] Preferably, in S1, the service information includes the service name, service code, version number, and whether the service address is found through service discovery.
[0023] This ensures the completeness and validity of the service information. Preferably, in S3, the product information includes product name, product code, and product routing strategy.
[0024] In this way, when a user's operation request comes in, the specific product can be located through the routing strategy in the product information, and then the complete access path of the specific API can be located by combining it with the request URL. Attached Figure Description
[0025] To make the objectives, technical solutions, and advantages of the invention clearer, the invention will now be described in further detail with reference to the accompanying drawings, wherein: Figure 1 This is a flowchart of the method of the present invention. Detailed Implementation
[0026] The following detailed explanation illustrates the specific implementation methods: Example: like Figure 1 As shown in the figure, this embodiment discloses a method for configuring and forwarding API gateways based on microservices, including the following steps: S1. Create the backend service and configure the service information; S2, API for creating services; S3. Create a product for external exposure and configure product information; S4. Bind products and services, establish the relationship between products and services, and generate operations under the bound service in batches through the API of the product. One operation corresponds to one API request for the service. It should be noted that global plugins do not need to be created, as they are already initialized and created by the system with preset execution periods. For example, a traffic statistics plugin is used to count the number of visits per hour by interface dimension.
[0027] S5. Create plugin groups and plugin instances under plugin groups according to requirements; S6. Create the relationship between operations and plugin groups, and specify the order of plugin groups under the same operation.
[0028] In practice, when creating the relationship between operations and plugin groups, the plugin groups are designated as personalized plugin groups. This allows for the creation of customized plugin groups based on specific user needs, facilitating the implementation of customized functions for each user. When creating the relationship between operations and plugin groups, one operation can be associated with multiple plugin groups, and one plugin group can also be associated with multiple different operations. This setup fully utilizes the existing plugin groups while ensuring the functionality and effectiveness of each operation.
[0029] S7. After receiving the user's operation, activate the service API request corresponding to the operation and execute the functions of the plugin group associated with the operation.
[0030] This method establishes relationships between services, APIs, and products after their creation, and generates operations for each product in batches via APIs under the services they are bound to. A product can correspond to multiple services, exposing a single product externally, but technically implemented by multiple microservices, ensuring separation of business and technology and a clearer hierarchy. Each operation represents an API request for a service, and the relative path of the API request is the same as the relative path of the API interface. Thus, when a user's operation request arrives, the routing strategy in the product information can locate the specific product, and combined with the request URL, the complete API access path can be determined. By importing and creating products associated with APIs, different APIs are bound to products, facilitating the creation of different access strategies for users. Furthermore, plugin groups and plugin instances within these groups can be created according to specific needs, establishing relationships between operations and plugin groups, and specifying the order of plugin groups under the same operation. Upon receiving a user's operation, the corresponding service API request can be activated, and the functionality of the associated plugin group can be executed. This allows for the development of a series of plugins to form a plugin chain, binding plugins or plugin groups according to API usage scenarios, and executing plugin logic to fulfill customized requirements during API access. Using an API gateway supports dynamic scaling without requiring deployment or modification of load balancers. When users need to integrate functions from different products or services and call capabilities provided by different services, the API gateway can complete interface assembly without being aware of edge services, reducing service exposure and increasing system security. This method is suitable for distributed API integration and large-scale API access while ensuring low latency. Customizable processes and requirements can be achieved through plugin configuration; dynamic API scaling eliminates the need for deployment and modification of load balancers, reducing operational costs and increasing system continuity. Furthermore, this method supports hot deployment of products and services. If a new product is released or the routing strategy is modified, there is no need to restart the system. After detecting product changes, the routing strategy can be loaded into memory, allowing for route assertion upon incoming requests. This method also supports hot plugin updates; if modifications to associated plugins or plugin configurations are required, the changes take effect immediately without a system restart.
[0031] This invention relates to a microservice-based API gateway configuration and forwarding method, which can be implemented as follows: First, create a service for internal request forwarding, entering the service name, service code, and version number. Optionally, service discovery can be used to find the service address; if not, the service address must be entered. Next, create an API, supporting both manual creation and batch import based on the OpenAPI protocol. After creation, API information can be manually modified, timeout configured, and APIs can be taken offline as needed. Then, create a product for external exposure, entering the product name, product code, and product routing strategy. Configuring the product routing strategy allows requests to be precisely routed to specific products. Bind products to services; one product can correspond to multiple services. This exposes a single product externally, but technically it is implemented by multiple microservices, ensuring separation of business and technology and a clearer hierarchy. Finally, generate operations in batches for the product, using APIs under the bound services to generate operations for that product in batches. Each operation represents a request, and the relative path of the request is the relative path of the interface. At this point, when a request comes in, the routing strategy can locate the specific product, and by combining it with the request URL, the complete access path to the specific API can be located.
[0032] Plugins in the system also function as filters, categorized into global plugins and personalized plugins. Global plugins execute on all requests, while personalized plugins can be bound to requests as needed. All plugins require definition, including plugin code, class path, and type. Plugin types are divided into pre-plugins and post-plugins, indicating whether they execute before request forwarding or after request forwarding but before the response, respectively. Configuration requirements within the plugin class also need to be defined, such as field names, codes, types, and entry methods. This allows operators to specify the necessary configuration information when generating specific plugin instances based on the plugin definitions. Then, plugin groups are created as needed, specifying the group name and order. Plugin instances are created within each group, specifying their order. The plugin selection range is the previously defined plugin types. If plugin configurations are defined, these must be specified when creating the plugin. Plugin groups are bound to operations as needed; an operation can be bound to multiple plugin groups, and a plugin group can belong to multiple different operations. Plugin groups are combined sequentially to form a plugin chain. All plugins are distinguished by their type and executed sequentially after a request arrives or before a response. Basic plugins such as authentication plugins, authorization plugins, and application purchase authentication plugins can be combined into plugin groups and then bound to operations. For example, operation A only requires user login to access, operation B requires user login and application purchase, and operation C requires user login, application purchase, and access permission. Based on these requirements, three plugin groups can be created: plugin group A contains only the authentication plugin, plugin group B contains both the authentication and application purchase authentication plugins, and plugin group C contains the authentication, application purchase authentication, and authorization plugins. These plugin groups can also be bound to other required operations. Global plugins do not need to be created; they are already initialized by the system and have preset execution periods. Traffic statistics plugins are used to count hourly accesses by interface dimension. Personalized plugins include authentication, authorization, application purchase authentication, request anti-fraud, request rate limiting, return code conversion, and detailed request logging.
[0033] Operators can create policies and bind them to product operations based on business needs. This step primarily determines whether a user has a corresponding policy when the authentication plugin is executed. Policies are categorized into allow and deny types. Allow means the operation can be executed, while deny means the operation cannot be executed. By binding policies to users as needed, the system can determine whether to allow the operation based on the policy type when a user makes a specific request.
[0034] The configuration information required for the main gateway process has been configured in the data table. The complete gateway process is described below: The following tasks will be performed during system startup: Step 1: Register the global plugin and the request route assertion filter. The filter will be executed first when a request arrives.
[0035] Step 2: Query all plugin instance configurations, and instantiate objects according to their plugin types and register them in the system.
[0036] Step 3: Query all product configurations, parse the routing policies configured for each product in turn, and write the policies into memory.
[0037] Step 4: Register a Redis listener to monitor changes in the product. If a change occurs, proceed to Step 2. Monitor changes in plugin instance configuration. If a new plugin is added, proceed to Step 3. If a plugin is deleted, remove the plugin from the system.
[0038] At the same time, another IAM management service will periodically read the database and load the configured service information, API information, plugin information, etc. into Redis.
[0039] After the request arrives, the execution process is as follows: Step 1: First, execute the route assertion filter. This filter will locate the request path to the specific operation and API based on the routing strategy and the configuration in Redis.
[0040] Step 2: Read all plugins under this operation from Redis and organize them in order with the system plugins to form a plugin chain.
[0041] Step 3: Execute the pre-installation plugins in sequence, such as traffic statistics, request parameter conversion, authentication, and authorization.
[0042] Step 4: Based on the API relative path and service path, concatenate the final forwarding address and forward the request.
[0043] Step 5: Execute post-plugins in sequence, such as return code conversion.
[0044] Step 6: Return response information.
[0045] The authentication plugin checks the token in the request header, retrieves the user information from Redis, and if successful, stores the user information in the request header and passes it on. If the user information cannot be retrieved from Redis, it calls the user center to retrieve the user information and stores it in Redis.
[0046] It can be designed to support hot deployment of products and services. If a new product is released or the routing strategy is modified, there is no need to restart the system. The system will listen for changes in products in Redis and load the routing strategy into memory, so that routing assertions can be performed when a request arrives.
[0047] Additionally, it can be designed to support hot updates of plugins. If it is necessary to modify the associated plugins or plugin configurations, the changes can take effect immediately without restarting the system. In specific implementation, after S6, S61 is also included, which creates policies for each operation and assigns policies to each user's account as needed; the policies include allowing or disallowing. In S7, after receiving a user's operation, it is also determined whether the operation is allowed based on the policy corresponding to that operation for that account. If allowed, the service API request corresponding to the operation is activated, and the functions of the plugin group associated with the operation are executed. This setting, by controlling user subscription access restrictions, can be effectively integrated with the enterprise's operational strategies. Furthermore, it also implements identity authentication and permission verification, improving the security of the distributed system and effectively avoiding the performance loss caused by independent authentication for each service.
[0048] In summary, the method of this invention can adapt to distributed API integration and large-scale API access while ensuring low latency; by binding with products, it controls user subscription access restrictions and effectively integrates with enterprise operational strategies; through plugin configuration and API interception, it can change API behavior and support customized processes and requirements; it provides a unified API access entry point to achieve identity authentication and permission verification, improving the security of distributed systems and effectively avoiding the performance loss caused by independent authentication for each service; using dynamic API expansion, it eliminates the need to deploy and modify load balancers, reducing operational costs and increasing the system's continuous service duration.
[0049] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and not to limit the technical solutions. Those skilled in the art should understand that any modifications or equivalent substitutions to the technical solutions of the present invention without departing from the spirit and scope of the present invention should be covered within the scope of the claims of the present invention.
Claims
1. A method for configuring and forwarding API gateways based on microservices, characterized in that, Includes the following steps: S1. The backend creates a service and configures the service information; the service information includes the service name, service code, version number, and whether to find the service address through service discovery. S2, API for creating services; S3. Create a product for external exposure and configure product information; the product information includes product name, product code, and product routing policy; S4. Bind products and services, establish the relationship between products and services, and generate operations under the product in batches through the API of the service bound to the product. One operation corresponds to one API request of the service. S5. Create plugin groups and plugin instances under plugin groups according to requirements; S6. Create the relationship between operations and plugin groups, and specify the order of plugin groups under the same operation; S7. After receiving the user's operation, activate the service API request corresponding to the operation and execute the function of the plugin group associated with the operation; S6 is followed by S61, which creates policies for each operation and assigns policies to each user's account as needed; the policies include allowing or disallowing. In S7, after receiving a user's operation, it also determines whether the operation is allowed based on the policy corresponding to the operation for that account. If allowed, it activates the service API request corresponding to the operation and executes the functions of the plugin group associated with the operation.
2. The method for configuring and forwarding an API gateway based on microservices as described in claim 1, characterized in that: In S5, the created plugin group is a personalized plugin group; in S6, when creating an operation and plugin group relationship, the plugin group is a personalized plugin group.
3. The method for configuring and forwarding an API gateway based on microservices as described in claim 2, characterized in that: In S6, when creating a relationship between an operation and a plugin group, an operation can be associated with multiple plugin groups, and a plugin group can also be associated with multiple different operations.
Citation Information
Patent Citations
API test method and system for service open platform
CN112632527A
Method and device for dynamically loading and configuring service gateway plug-in
CN115102849A
