A rule-based URL routing implementation method and system

CN116915684BActive Publication Date: 2026-09-01北京中睿天下信息技术有限公司
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310985834.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-08-07
Publication Date
2026-09-01
Estimated Expiration
2043-08-07

AI Technical Summary

Technical Problem

[0005]为此,本发明实施例提供一种基于规则配置的URL路由实现方法及系统,以解决现有技术修改路由规则需要重新编译程序,重新登陆到服务器更新程序的技术问题

Benefits of technology

[0031]本发明实施例在需要对URL路由规则进行调整时,从预设JSON配置文件中加载URL路由配置规则,从来自客户端的HTTP请求中提取请求方法、URL地址,利用URL路由匹配规则对所述请求方法、URL地址进行逐个比对;当所述比对结果符合时,将URL路由匹配规则中的预设结构定义及相关信息发送至客户端;根据客户端接收到的信息决定是否输出响应正文、预定义字符串内容、输出文件内容。本发明实施例通过远程下发的方式动态调整URL路由匹配规则,可以随时调整不同URL路由下响应的数据内容,调整后的URL路由规则可以通过预留的API接口直接更新,无需修改程序,降低了程序的维护难度与维护成本,提高了程序整体可用性。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116915684B_ABST
    Figure CN116915684B_ABST
Patent Text Reader

Abstract

This invention discloses a rule-based URL routing implementation method and system. When URL routing rules need adjustment, this invention loads URL routing configuration rules from a preset JSON configuration file, extracts the request method and URL address from the HTTP request from the client, and compares the request method and URL address one by one using URL routing matching rules. When the comparison result matches, the preset structure definition and related information in the URL routing matching rules are sent to the client. Based on the information received by the client, it is determined whether to output the response body, predefined string content, or output file content. This invention dynamically adjusts the URL routing matching rules through remote distribution, allowing for adjustments to the response data content under different URL routes at any time. The adjusted URL routing rules can be directly updated through a reserved API interface without modifying the program, reducing the difficulty and cost of program maintenance and improving the overall usability of the program.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of wireless communication technology, specifically to a method and system for implementing URL routing based on rule configuration. Background Technology

[0002] Routing policies are techniques for modifying routing information to change the path network traffic takes, primarily by altering route attributes. Routing policies can be used to control route publishing, route receiving, manage incoming routes, and set route attributes. They can dynamically execute different program logic or data based on different request methods and URLs.

[0003] The current mainstream methods for implementing URL routing are fixed during the application development process; requests matching a specific URL route will respond with specific data. If the routing rules need to be adjusted, the application source code needs to be modified, and then each application needs to be redeployed to the application server. Upgrading the application often causes service interruptions.

[0004] The entire process is rather cumbersome and may cause interruptions for users accessing the service due to various reasons, affecting user experience. If the business is more flexible, routing rules need to be adjusted frequently, wasting a lot of time and energy on upgrades and maintenance. Summary of the Invention

[0005] To address this issue, this invention provides a rule-based URL routing implementation method and system to solve the technical problem that modifying routing rules in the prior art requires recompiling the program and logging back into the server to update the program.

[0006] To achieve the above objectives, the embodiments of the present invention provide the following technical solutions:

[0007] According to a first aspect of the present invention, a method for implementing URL routing based on rule configuration is provided, the method comprising:

[0008] S1. Load the URL routing configuration rules from the preset JSON configuration file and store the URL routing configuration rules in memory;

[0009] S2. Upon receiving an HTTP request from the client, extract the request method and URL address from the HTTP request, and compare the request method and URL address one by one using URL routing matching rules to generate a comparison result;

[0010] S3. When the comparison result matches, the information is sent to the client according to the preset structure definition and related information in the URL routing matching rules.

[0011] S4. Based on the HTTP response body body type in the structure definition and related information, determine whether to output the response body, predefined string content, or output file content.

[0012] Furthermore, the URL routing configuration rules are stored in a JSON configuration file, which specifically describes the URL routing matching rules and the data structure description of the response after matching.

[0013] Furthermore, the JSON configuration file describes the HTTP request method, URL routing matching rules, HTTP request status code, HTTP request header information list, HTTP response body body type, and response body body content / file address;

[0014] The URL routing matching rules include the URL matching method, the URL matching range, and the string or regular expression description string used for URL matching.

[0015] Furthermore, the structure definition and related information include the status code and HTTP request header information in response to the client's HTTP request.

[0016] Furthermore, if the body of the HTTP response is of type file, the file address specified in the description is read, the file is read, and the file is output to the response body.

[0017] Preferably, a rule-based URL routing implementation method further includes:

[0018] Retrieve a URL routing matching rule;

[0019] Determine whether the URL routing matching rule matches the HTTP request;

[0020] If the URL routing matching rule matches the HTTP request, then the HTTP request information is saved and a response is generated;

[0021] If the URL routing matching rule does not match the HTTP request, then determine whether the URL routing matching rule is the last rule;

[0022] If the URL routing match rule is the last rule, then output a 404 message;

[0023] If the URL routing matching rule is not the last rule, then obtain the URL routing matching rule again.

[0024] Furthermore, when the URL matching rules change, a new JSON configuration file is uploaded through a preset API interface, overwriting the original JSON configuration file. Starting from step S1, the new JSON configuration file is reloaded and updated in memory.

[0025] According to a second aspect of the present invention, a rule-based URL routing implementation system is provided, the system comprising:

[0026] The loading module is used to load URL routing configuration rules from a preset JSON configuration file and store the URL routing configuration rules in memory;

[0027] The comparison module is used to receive HTTP requests from clients, extract request methods and URL addresses from the HTTP requests, compare the request methods and URL addresses one by one using URL routing matching rules, and generate comparison results.

[0028] The sending module is used to send the data to the client according to the preset structure definition and related information in the URL routing matching rules when the comparison result matches.

[0029] The output module is used to determine whether to output the response body, predefined string content, or output file content based on the HTTP response body body type in the structure definition and related information.

[0030] The embodiments of the present invention have the following advantages:

[0031] In this embodiment of the invention, when adjustments to URL routing rules are needed, URL routing configuration rules are loaded from a preset JSON configuration file. The request method and URL address are extracted from the HTTP request from the client, and the request method and URL address are compared one by one using URL routing matching rules. When the comparison result matches, the preset structure definition and related information in the URL routing matching rules are sent to the client. Based on the information received by the client, it is determined whether to output the response body, predefined string content, or output file content. This embodiment of the invention dynamically adjusts URL routing matching rules through remote distribution, allowing for adjustments to the response data content under different URL routes at any time. The adjusted URL routing rules can be directly updated through a reserved API interface without modifying the program, reducing the difficulty and cost of program maintenance and improving the overall usability of the program. Attached Figure Description

[0032] To more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings in the following description are merely exemplary, and those skilled in the art can derive other embodiments based on the provided drawings without creative effort.

[0033] The structures, proportions, sizes, etc. illustrated in this specification are only for the purpose of assisting those skilled in the art in understanding and reading the content disclosed herein, and are not intended to limit the conditions under which the present invention can be implemented. Therefore, they have no substantial technical significance. Any modifications to the structure, changes in the proportions, or adjustments to the size, without affecting the effects and objectives that the present invention can produce, should still fall within the scope of the technical content disclosed in the present invention.

[0034] Figure 1 A schematic diagram of the logical structure of a rule-based URL routing implementation system provided in an embodiment of the present invention;

[0035] Figure 2 This is a first flowchart illustrating a rule-based URL routing implementation method according to an embodiment of the present invention.

[0036] Figure 3 This is a second flowchart illustrating a rule-based URL routing implementation method provided in an embodiment of the present invention. Detailed Implementation

[0037] The following specific embodiments illustrate the implementation of the present invention. Those skilled in the art can easily understand other advantages and effects of the present invention from the content disclosed in this specification. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0038] The current mainstream methods for implementing URL routing are fixed during the application development process; requests matching a specific URL route will respond with specific data. If the routing rules need to be adjusted, the application source code needs to be modified, and then each application needs to be redeployed to the application server. Upgrading the application often causes service interruptions.

[0039] The entire process is rather cumbersome and may interrupt the access for users due to various reasons, affecting user experience. If the business is more flexible, it requires frequent adjustments to routing rules, wasting a lot of time and effort on upgrades and maintenance.

[0040] To address the technical issue of needing to recompile the program and log back into the server to update it when modifying routing rules.

[0041] refer to Figure 1 This invention discloses a rule-based URL routing implementation system, which includes: a loading module 1, a comparison module 2, a sending module 3, and an output module 4.

[0042] Loading module 1 loads URL routing configuration rules from a preset JSON configuration file and stores the URL routing configuration rules in memory, such as... Figure 2 As shown, after receiving an HTTP request from the client, the comparison module 2 extracts the request method and URL address from the HTTP request, and compares the request method and URL address one by one using the URL routing matching rules to generate a comparison result. When the comparison result matches, the sending module 3 sends the request to the client according to the preset structure definition and related information in the URL routing matching rules. The output module 4 determines whether to output the response body, predefined string content, or output file content based on the body type of the HTTP response body in the structure definition and related information.

[0043] Corresponding to the rule-based URL routing implementation system disclosed above, this invention also discloses a rule-based URL routing implementation method. The following details a rule-based URL routing implementation method disclosed in this invention, in conjunction with the rule-based URL routing implementation system described above.

[0044] refer to Figure 2 The method includes: S1, loading URL routing configuration rules from a preset JSON configuration file and storing the URL routing configuration rules in memory; S2, receiving an HTTP request from a client, extracting the request method and URL address from the HTTP request, and comparing the request method and URL address one by one using URL routing matching rules to generate a comparison result; S3, when the comparison result matches, sending it to the client according to the preset structure definition and related information in the URL routing matching rules; S4, determining whether to output the response body, predefined string content, or output file content according to the body type of the HTTP response body in the structure definition and related information.

[0045] The URL (Uniform Resource Locator) routing configuration rules are stored in a JSON configuration file, which describes the URL routing matching rules and the data structure of the response after matching.

[0046] JSON (JavaScript Object Notation) is a lightweight data interchange format whose content consists of attributes and values. JSON is based on a subset of ECMAScript (the JavaScript specification developed by the European Computer Manufacturers Association) and uses a text format that is completely independent of programming languages ​​to store and represent data.

[0047] The comparison method will select different comparison methods according to different URL routing description rules. It can use text search or regular expression matching to search or match in the complete URL path or the path part of the URL path according to the URL routing description rules.

[0048] Furthermore, the JSON configuration file describes the HTTP request method, URL routing matching rules, HTTP request status code, HTTP request header list, HTTP response body body type, and response body content / file address.

[0049] The preset structure definition and related information are the structure definition information and related information that are responded to by the client when the rule is hit.

[0050] HTTP stands for Hypertext Transfer Protocol.

[0051] The URL routing matching rules include the URL matching method, the URL matching range, and the string or regular expression description string used for URL matching.

[0052] Furthermore, the structure definition and related information include the status code and HTTP request header information in response to the client's HTTP request.

[0053] Furthermore, if the body of the HTTP response is of type file, the file address specified in the description is read, the file is read, and the file is output to the response body.

[0054] refer to Figure 3The system retrieves a URL routing matching rule; determines whether the URL routing matching rule matches an HTTP request; if the URL routing matching rule matches the HTTP request, it saves the HTTP request information and generates a response; if the URL routing matching rule does not match the HTTP request, it determines whether the URL routing matching rule is the last rule; if the URL routing matching rule is the last rule, it outputs a 404 message; if the URL routing matching rule is not the last rule, it retrieves a new URL routing matching rule.

[0055] Furthermore, when the URL matching rules change, a new JSON configuration file is uploaded through a preset API interface, overwriting the original JSON configuration file. Starting from step S1, the new JSON configuration file is reloaded and updated in memory.

[0056] Those skilled in the art will recognize that, in one or more of the examples above, the functions described in this invention can be implemented using a combination of hardware and software. When applied as software, the corresponding functions can be stored in a computer-readable medium or transmitted as one or more instructions or code on a computer-readable medium. Computer-readable media include computer storage media and communication media, wherein communication media include any medium that facilitates the transmission of computer programs from one place to another. Storage media can be any available medium that can be accessed by a general-purpose or special-purpose computer.

[0057] Although the present invention has been described in detail above with general descriptions and specific embodiments, modifications or improvements can be made to it, which will be obvious to those skilled in the art. Therefore, all such modifications or improvements made without departing from the spirit of the present invention fall within the scope of protection claimed by the present invention.

Claims

1. A method for implementing URL routing based on rule configuration, characterized in that, The method includes: S1. Load the URL routing configuration rules from the preset JSON configuration file and store the URL routing configuration rules in memory; S2. Upon receiving an HTTP request from the client, extract the request method and URL address from the HTTP request, and compare the request method and URL address one by one using URL routing matching rules to generate a comparison result; S3. When the comparison result matches, the information is sent to the client according to the preset structure definition and related information in the URL routing matching rules. S4. Based on the HTTP response body body type in the structure definition and related information, determine whether to output the response body, predefined string content, or output file content; The JSON configuration file describes the HTTP request method, URL routing matching rules, HTTP request status code, HTTP request header list, HTTP response body body type, and response body content / file address. The URL routing matching rules include the URL matching method, the URL matching range, and a string or regular expression description string used for URL matching; The structure definition and related information include the status code and HTTP request header information in response to client HTTP requests; When the URL matching rules change, a new JSON configuration file is uploaded through a preset API interface, and the original JSON configuration file is overwritten. Starting from step S1, the new JSON configuration file is reloaded and updated in memory.

2. The URL routing implementation method based on rule configuration as described in claim 1, characterized in that, The URL routing configuration rules are stored in a JSON configuration file, which describes the URL routing matching rules and the data structure of the response after matching.

3. The URL routing implementation method based on rule configuration as described in claim 1, characterized in that, If the body of the HTTP response is of type file, the file address specified in the description is read, the file is read, and the file is output to the response body.

4. The URL routing implementation method based on rule configuration as described in claim 3, characterized in that, The method further includes: Retrieve a URL routing matching rule; Determine whether the URL routing matching rule matches the HTTP request; If the URL routing matching rule matches the HTTP request, then the HTTP request information is saved and a response is generated; If the URL routing matching rule does not match the HTTP request, then determine whether the URL routing matching rule is the last rule; If the URL routing match rule is the last rule, then output a 404 message; If the URL routing matching rule is not the last rule, then obtain the URL routing matching rule again.

5. A URL routing implementation system based on rule configuration, characterized in that, The system includes: The loading module is used to load URL routing configuration rules from a preset JSON configuration file and store the URL routing configuration rules in memory; The comparison module is used to receive HTTP requests from clients, extract request methods and URL addresses from the HTTP requests, compare the request methods and URL addresses one by one using URL routing matching rules, and generate comparison results. The sending module is used to send the data to the client according to the preset structure definition and related information in the URL routing matching rules when the comparison result matches. The output module is used to determine whether to output the response body, predefined string content, or output file content based on the HTTP response body body type in the structure definition and related information. The JSON configuration file describes the HTTP request method, URL routing matching rules, HTTP request status code, HTTP request header list, HTTP response body body type, and response body content / file address. The URL routing matching rules include the URL matching method, the URL matching range, and a string or regular expression description string used for URL matching; The structure definition and related information include the status code and HTTP request header information in response to client HTTP requests; When the URL matching rules change, a new JSON configuration file is uploaded through a preset API interface, the original JSON configuration file is overwritten, the new JSON configuration file is reloaded, and the updated JSON configuration file is overwritten and updated in memory.

Citation Information

Patent Citations

  • Decentralization automatic routing method

    CN114172805A

  • Service request processing method, system and device

    CN114500481A