Processing method for site-dependent API (Application Program Interface)

By uniformly configuring the API interface into XML files and asynchronously loading API requests using thread pools, the problems of API dependency maintenance and lack of monitoring in the existing technology are solved, and efficient API management and monitoring are achieved.

CN119415284APending Publication Date: 2025-02-11CHEZHI HULIAN BEIJING SCI & TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411441261.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-15
Publication Date
2025-02-11

AI Technical Summary

Technical Problem

The existing site-dependent API processing methods are difficult to maintain when dealing with a large number of API dependencies, changes are prone to errors, and lack unified monitoring and cache management.

Method used

Unified configuration and management are achieved by configuring all line-of-business APIs that the web site depends on into XML files. Supports API grouping, cache, timeout and other configurations, uses thread pools to load API requests asynchronously, and records slow logs and alarms.

Benefits of technology

It realizes unified management and maintenance of a large number of API dependencies, improves server throughput and response speed, facilitates troubleshooting of abnormal problems, and provides real-time monitoring and alarm mechanisms.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119415284A_ABST
    Figure CN119415284A_ABST
Patent Text Reader

Abstract

The invention belongs to the technical field of data processing, and discloses a site-dependent API (Application Program Interface) processing method, which comprises the following steps of: 1, reading configuration information of all requested API interfaces in an XML (Extensible Markup Language) file in the XML file configured by APIs of all service lines on which a Web site depends; service line API grouping is supported, each service line is divided into one group, and cache, timeout and other information can be independently configured for the service line. According to the method, external service line APIs on which Web sites depend are uniformly configured in the XML for management and maintenance through the first step and the third step, cache strategies and the like can be configured, and different API interfaces can be configured in different XML environments; 4, a quick response API and a fault-tolerant mechanism are provided through cache configuration; 5, realizing multi-thread asynchronous loading of the API interface to improve the throughput of the server; 7, recording a slow log and giving an alarm when the slow log exceeds a threshold value; and step 9 and step 10, dynamically monitoring API information on which the page depends and displaying debugging information, thereby facilitating troubleshooting of abnormal problems.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of data processing, and in particular relates to a method for processing a site-dependent API. Background Art

[0002] Each Autohome site is independent of its business line, and each business line maintains its own business data. When business line A depends on business line B, business line B provides an API interface for business line A to call. In this way, each business line is independent of each other and the site is relatively lightweight. However, the Web site relies on a large number of API interfaces from other business lines. How to call, configure, and monitor these interfaces, as well as uniformly manage and cache data and understand the time consumption of calls have become important tasks.

[0003] The existing site dependency API processing method is to directly add the API interface dependency code. This method is direct and simple and can directly see the specific dependent API interface and the API interface call parameters. However, the disadvantage of this method is that it is not suitable for a large number of API dependencies. Each change must find the specific dependency location and modify it. When a large business line relies heavily on the API interfaces of other business lines, it is difficult to maintain, changes are prone to errors, and there is no unified monitoring place. The API result cache is also maintained separately, which is not suitable for the situation of a large number of API interface dependencies, so it needs to be improved. Summary of the invention

[0004] The purpose of the present invention is to provide a method for processing site-dependent APIs to solve the problems raised in the above background technology.

[0005] In order to achieve the above object, the present invention provides the following technical solution: a method for processing a site-dependent API, comprising the following steps:

[0006] Step 1: Put the API configuration XML file of all business lines that the Web site depends on. All requested API interfaces must read the configuration information in the XML file; support business line API grouping, each business line is divided into a group, and cache, timeout and other information can be configured separately for the business line;

[0007] Step 2: Determine whether the API interface that the page depends on is in the XML configuration file in step 1. If not, an alarm is issued. If yes, proceed to step 3.

[0008] Step 3: Read the cache information, timeout settings, and encoding method configured in the API interface, and encapsulate the request;

[0009] Step 4: Before making a specific API request, determine whether the API request is cached. If so, directly read the cache and return. Otherwise, proceed to step 5.

[0010] Step 5: Start the thread pool to asynchronously load the API request. If the request fails, proceed to step 6. If the request succeeds, proceed to step 7.

[0011] Step 6: Determine whether there is a cached result for the failed request. If so, proceed to step 9; otherwise, terminate the request.

[0012] Step 7: When the API request is successful, determine whether the request takes longer than 1 second. If so, record it in the database. The scheduled task program calculates too many API requests that have timed out and issues an alarm.

[0013] Step 8: Process the above API interface results according to the cache policy according to the XML configuration cache information;

[0014] Step 9: All API requests can be intercepted and processed uniformly to determine whether to monitor API information. If API monitoring is required, the API information is recorded and output to facilitate troubleshooting.

[0015] Step 10: Output the API results to the page, completing the entire page API request process.

[0016] Preferably, the API interface described in step one is set with a long cache time and a short cache validity time, and the short cache validity time is set to ten minutes.

[0017] Preferably, the warning methods adopted by the warning described in step 2 include pop-up window warning and sound prompt, the pop-up window warning cannot be closed at will, and the sound prompt can be adjusted in size at will.

[0018] Preferably, the encapsulation methods used in the encapsulation described in step three include programming language encapsulation, configuration file encapsulation, environment variable encapsulation and configuration center encapsulation, and the configuration files in the configuration file encapsulation include JSON configuration files and YAML configuration files.

[0019] Preferably, the total number of threads in the thread pool described in step 5 is 256 by default, and the total number of threads in the thread pool can be increased as needed.

[0020] Preferably, the database described in step seven is provided with security measures, and the methods of the security measures include data encryption and access control.

[0021] Preferably, the timeout period of the calculation timeout described in step seven defaults to one hundred and twenty seconds, and the timeout period can be modified according to user needs.

[0022] Preferably, the interception method adopted by the interception processing described in step nine is AOP interception, and the interception method can be modified later.

[0023] Preferably, the monitoring method adopted by the monitoring API described in step nine is log recording, and the monitoring method includes log recording, performance indicator monitoring and health monitoring.

[0024] The beneficial effects of the present invention are as follows:

[0025] The present invention configures the external business line APIs that the Web site relies on in a unified manner in XML for management and maintenance through steps 1 and 3, and can configure cache strategies, etc. Different XML environments can configure different API interfaces; step 4 uses cache configuration to provide a fast response API and fault tolerance mechanism; step 5 implements multi-threaded asynchronous loading of API interfaces to improve server throughput; step 7 records slow logs and issues an alarm when a threshold is exceeded;

[0026] Steps 9 and 10 dynamically monitor the API information that the page depends on and display debugging information to facilitate troubleshooting of abnormal problems. BRIEF DESCRIPTION OF THE DRAWINGS

[0027] Figure 1 It is a schematic diagram of the process of the present invention. DETAILED DESCRIPTION

[0028] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0029] like Figure 1 As shown, an embodiment of the present invention provides a method for processing a site-dependent API, comprising the following steps:

[0030] Step 1: Put the API configuration XML file of all business lines that the Web site depends on. All requested API interfaces must read the configuration information in the XML file; support business line API grouping, each business line is divided into a group, and cache, timeout and other information can be configured separately for the business line;

[0031] Step 2: Determine whether the API interface that the page depends on is in the XML configuration file in step 1. If not, an alarm is issued. If yes, proceed to step 3.

[0032] Step 3: Read the cache information, timeout settings, and encoding method configured in the API interface, and encapsulate the request;

[0033] Step 4: Before making a specific API request, determine whether the API request is cached. If so, directly read the cache and return. Otherwise, proceed to step 5.

[0034] Step 5: Start the thread pool to asynchronously load the API request. If the request fails, proceed to step 6. If the request succeeds, proceed to step 7.

[0035] Step 6: Determine whether there is a cached result for the failed request. If so, proceed to step 9; otherwise, terminate the request.

[0036] Step 7: When the API request is successful, determine whether the request takes longer than 1 second. If so, record it in the database. The scheduled task program calculates too many API requests that have timed out and issues an alarm.

[0037] Step 8: Process the above API interface results according to the cache policy according to the XML configuration cache information;

[0038] Step 9: All API requests can be intercepted and processed uniformly to determine whether to monitor API information. If API monitoring is required, the API information is recorded and output to facilitate troubleshooting.

[0039] Step 10: Output the API results to the page, completing the entire page API request process.

[0040] This solution implements a unified configuration of API interfaces, facilitates unified maintenance of business line API dependencies, unified configuration of caches, and other issues. When dealing with Web sites that rely heavily on business party APIs, it has the characteristics of configurable management, real-time monitoring, and convenient cache modification.

[0041] The API interface in step one is set with a long cache time and a short cache validity time, and the short cache validity time is set to ten minutes.

[0042] This design enables users to obtain content directly from the cache, reducing server load and response time.

[0043] Among them, the alarm methods adopted by the alarm in step 2 include pop-up alarm and sound prompt. The pop-up alarm cannot be closed at will, and the sound prompt can be adjusted in size at will.

[0044] The design that the pop-up alarm cannot be closed at will prevents staff from missing the alarm content, and the volume can be adjusted at will to meet the needs of different staff.

[0045] Among them, the encapsulation methods adopted in step three include programming language encapsulation, configuration file encapsulation, environment variable encapsulation and configuration center encapsulation, and the configuration files in the configuration file encapsulation include JSON configuration files and YAML configuration files.

[0046] These four encapsulation methods all ensure the security, maintainability, and scalability of API interface configuration.

[0047] Among them, the total number of threads in the thread pool in step 5 is 256 by default, and the total number of threads in the thread pool can be increased as needed.

[0048] The threads in the thread pool will continuously obtain tasks from the task queue and execute them. When a thread completes a task, it will continue to obtain the next task from the task queue until the task queue is empty.

[0049] The database in step seven is provided with security measures, and the security measures include data encryption and access control.

[0050] Such a design can ensure the security of the database and avoid the risk of data leakage.

[0051] The default timeout period for the calculation timeout in step 7 is 120 seconds, and the timeout period can be modified according to user needs.

[0052] This design improves work efficiency and system reliability.

[0053] Among them, the interception method used in the interception processing in step nine is AOP interception, and the interception method can be modified later.

[0054] The design of AOP interception can intercept and enhance specific methods or code blocks in the program without modifying the original code.

[0055] The monitoring method used by the monitoring API in step nine is logging, which includes logging, performance indicator monitoring, and health monitoring.

[0056] By monitoring the operation of the API, problems can be discovered in a timely manner and measures can be taken to resolve them, ensuring the stability, reliability and high performance of the API.

[0057] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device.

[0058] Although embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present invention, and that the scope of the present invention is defined by the appended claims and their equivalents.

Claims

1. A method for processing a site-dependent API, characterized in that: The following steps are involved: Step 1: Put the API configuration XML file of all business lines that the Web site depends on. All requested API interfaces must read the configuration information in the XML file; support business line API grouping, each business line is divided into a group, and cache, timeout and other information can be configured separately for the business line; Step 2: Determine whether the API interface that the page depends on is in the XML configuration file in step 1. If not, an alarm is issued. If yes, proceed to step 3. Step 3: Read the cache information, timeout settings, and encoding method configured in the API interface, and encapsulate the request; Step 4: Before making a specific API request, determine whether the API request is cached. If so, directly read the cache and return. Otherwise, proceed to step 5. Step 5: Start the thread pool to asynchronously load the API request. If the request fails, proceed to step 6. If the request succeeds, proceed to step 7. Step 6: Determine whether there is a cached result for the failed request. If so, proceed to step 9; otherwise, terminate the request. Step 7: When the API request is successful, determine whether the request takes longer than 1 second. If so, record it in the database. The scheduled task program calculates too many API requests that have timed out and issues an alarm. Step 8: Process the above API interface results according to the cache policy according to the XML configuration cache information; Step 9: All API requests can be intercepted and processed uniformly to determine whether to monitor API information. If API monitoring is required, the API information is recorded and output to facilitate troubleshooting. Step 10: Output the API results to the page, completing the entire page API request process.

2. A method for processing a site-dependent API according to claim 1, characterized in that: The API interface described in step one is set with a long cache time and a short cache validity time, and the short cache validity time is set to ten minutes.

3. A method for processing a site-dependent API according to claim 1, characterized in that: The warning methods adopted by the warning described in step 2 include pop-up window warning and sound prompt. The pop-up window warning cannot be closed at will, and the sound prompt can be adjusted in size at will.

4. A method for processing a site-dependent API according to claim 1, characterized in that: The encapsulation methods used in the encapsulation described in step three include programming language encapsulation, configuration file encapsulation, environment variable encapsulation and configuration center encapsulation. The configuration files in the configuration file encapsulation include JSON configuration files and YAML configuration files.

5. A method for processing a site-dependent API according to claim 1, characterized in that: The total number of threads in the thread pool described in step 5 is 256 by default, and the total number of threads in the thread pool can be increased as needed.

6. A method for processing a site-dependent API according to claim 1, characterized in that: The database described in step seven is provided with security measures, and the methods of the security measures include data encryption and access control.

7. A method for processing a site-dependent API according to claim 1, characterized in that: The timeout period for the calculation timeout described in step seven is one hundred and twenty seconds by default, and the timeout period can be modified according to user needs.

8. A method for processing a site-dependent API according to claim 1, characterized in that: The interception method used in the interception process described in step nine is AOP interception, and the interception method can be modified later.

9. A method for processing a site-dependent API according to claim 1, characterized in that: The monitoring method adopted by the monitoring API described in step nine is log recording, and the monitoring method includes log recording, performance indicator monitoring and health monitoring.