Interface configuration method and system

文档序号:7369 发布日期:2021-09-17 浏览:98次 中文

1. An interface configuration method, comprising the steps of:

intercepting a request initiated by a client through proxy service;

analyzing the request, determining a matched preset conversion interface, and initiating a new request to the server by using the obtained preset conversion interface;

the server side outputs the request response result to the proxy service, the proxy service carries out reduction processing according to the original request API interface, and the response result after the reduction processing is issued to the client side.

2. The interface configuration method of claim 1, wherein the analyzing the request comprises: and when the preset conversion interface is matched, suspending the original request for waiting.

3. The interface configuration method of claim 2, wherein the analyzing the request further comprises: and if the matching fails to the preset conversion interface, the server side responds to the original request and directly sends the response result to the client side.

4. The interface configuration method of claim 3, wherein analyzing the request comprises, prior to: acquiring a URL (uniform resource locator) and a request method of a request;

the proxy service provides a preset URL and a preset request method, and when the requested URL and the request method are matched with the preset URL and the preset request method, a preset conversion interface is determined.

5. The interface configuration method of claim 4, wherein the analyzing the request further comprises: acquiring one or more of a message header, a URL parameter and a message body of the request;

the proxy service also provides one or more of a preset message header, a preset URL parameter and a preset message body, and when one or more conditions that the requested message header is matched with the preset message header, the URL parameter is matched with the preset URL parameter or the message body is matched with the preset message body are met, the preset conversion interface is determined.

6. An interface matching system, comprising: the system comprises a client, a proxy service and a server;

the client is used for initiating a request;

the proxy service comprises an attribute analysis module, an analysis module and a restoration module,

the attribute analysis module is used for intercepting a request initiated by a client and analyzing request attributes, wherein the request attributes comprise a Uniform Resource Locator (URL), a request method and one or more of a message header, a URL parameter and a message body;

the analysis module is used for analyzing whether the request attribute is matched with a preset request attribute, determining a preset conversion interface when the request attribute is matched with the preset request attribute, suspending the original request for waiting, and sending the original request to the server if the original request is not matched with the preset conversion interface, wherein the preset request attribute comprises a preset URL (uniform resource locator), a preset request method and one or more of a preset message header, a preset URL parameter and a preset message body;

the restoration module is used for restoring the request response result output by the server according to the original request API interface and sending the response result after restoration to the client;

and the server is used for outputting a response result according to the request, wherein when the received request is a new request, the response result is output to the restoration module, and when the received request is an original request, the response result is directly issued to the client.

Background

With the rapid development of computer technology, a large number of APPs and applets are produced, developers often need to constantly develop new versions for specific services, for example, after a new APP and an interface are developed, the interface is incompatible with an old interface of a client, and a conventional processing mode includes APP forced update, hot update, proxy service and the like, wherein the forced update affects user experience and easily causes user loss; after the hot update is modified, the hot update needs to be modified in the native code; while proxy services, such as Nginx, may forward a fixed service or perform a fixed code according to a service rule to perform interface forwarding, but have high limitations and are not capable of flexible configuration management. In addition, the existing numerous proxy services cannot flexibly configure interface information. Developers who have code capacity need to encode according to business requirements to realize fixed forwarding function, and the system has poor expansibility and cannot multiplex.

Disclosure of Invention

The invention aims to provide an interface configuration method and system, wherein clients of new and old versions can enjoy the latest interface service, and the server does not need to consider the interface compatibility of the old versions too much, so that the problems in the background technology are effectively solved.

In order to realize the purpose, the invention is realized by the following technical scheme: an interface configuration method comprises the following steps:

intercepting a request initiated by a client through proxy service;

analyzing the request, determining a matched preset conversion interface, and initiating a new request to the server by using the obtained preset conversion interface;

the server side outputs the request response result to the proxy service, the proxy service carries out reduction processing according to the original request API interface, and the response result after the reduction processing is issued to the client side.

According to a preferred embodiment, the interface configuration method further includes: and when the preset conversion interface is matched, suspending the original request for waiting.

According to a preferred embodiment, the interface configuration method further includes: and if the matching fails to the preset conversion interface, the server side responds to the original request and directly sends the response result to the client side.

According to a preferred embodiment, said analyzing of the request comprises, before: the proxy service provides a preset URL and a preset request method, and when the requested URL and the requested method are matched with the preset URL and the preset request method, a preset conversion interface is determined.

According to a preferred embodiment, said analyzing the request further comprises: acquiring one or more of a message header, a URL parameter and a message body of the request; the proxy service also provides one or more of a preset message header, a preset URL parameter and a preset message body, and when one or more conditions that the requested message header is matched with the preset message header, the URL parameter is matched with the preset URL parameter or the message body is matched with the preset message body are met, the preset conversion interface is determined.

The present invention also provides an interface matching system, comprising: the system comprises a client, a proxy service and a server;

the client is used for initiating a request;

the proxy service comprises an attribute analysis module, an analysis module and a restoration module,

the attribute analysis module is used for intercepting a request initiated by a client and analyzing request attributes, wherein the request attributes comprise a Uniform Resource Locator (URL), a request method and one or more of a message header, a URL parameter and a message body;

the analysis module is used for analyzing whether the request attribute is matched with a preset request attribute, determining a preset conversion interface when the request attribute is matched with the preset request attribute, suspending the original request for waiting, and sending the original request to the server if the original request is not matched with the preset conversion interface, wherein the preset request attribute comprises a preset URL (uniform resource locator), a preset request method and one or more of a preset message header, a preset URL parameter and a preset message body;

the restoration module is used for restoring the request response result output by the server according to the original request API interface and sending the response result after restoration to the client;

and the server is used for outputting a response result according to the request, wherein when the received request is a new request, the response result is output to the restoration module, and when the received request is an original request, the response result is directly issued to the client.

The technical scheme of the embodiment of the invention at least has the following advantages and beneficial effects: 1) the configuration method has low requirement on the coding capacity, and other personnel except developers can easily configure the interface information, thereby maximizing the expansibility; 2) the user does not need to update the version, and can also obtain the service data which is only supported by the latest interface through the API request of the old version, so that the user experience is enhanced; 3) on the system architecture separated from the front end and the back end, the constraint of version consistency is separated again, particularly, the seamless conversion is realized in the using process depending on the third party audit or the program which cannot be automatically updated by the client, so that the version iteration has no compatible burden of an interface.

Drawings

Fig. 1 is a schematic flowchart of an interface configuration method according to embodiment 1 of the present invention;

fig. 2 is a block diagram of an interface configuration system according to embodiment 1 of the present invention;

fig. 3 is a schematic diagram of a configuration method provided in embodiment 1 of the present invention.

Detailed Description

In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, but not all, embodiments of the present invention. The components of embodiments of the present invention generally described and illustrated in the figures herein may be arranged and designed in a wide variety of different configurations.

Example 1

Referring to fig. 1, fig. 1 is a schematic flowchart illustrating an interface configuration method according to an embodiment of the present invention.

The applicant researches and discovers that aiming at the problem that after a new APP and an interface are developed, the interface is incompatible with an old interface of a client, conventional processing modes comprise APP forced updating, hot updating, proxy service and the like, wherein the forced updating influences user experience and easily causes user loss; after the hot update is modified, the hot update needs to be modified in the native code; while proxy services, such as Nginx, may forward a fixed service or perform a fixed code according to a service rule to perform interface forwarding, but have high limitations and are not capable of flexible configuration management. In addition, the existing numerous proxy services cannot flexibly configure interface information. Developers who have code capacity need to encode according to business requirements to realize fixed forwarding function, and the system has poor expansibility and cannot multiplex. Therefore, the invention provides an interface configuration method and system, the clients of the new and old versions can enjoy the latest interface service, and the server does not need to consider the interface compatibility of the old version too much. The specific scheme is as follows:

referring to the schematic diagram of the configuration method shown in fig. 3, an interface configuration method includes the following steps:

intercepting a request initiated by a client through proxy service; wherein the key attributes of the request include: domain name (Domain), route (Url), request Method (Method), Header (Header), URL Parameters (Parameters), and Body (Body).

Further, after the agent service intercepts the Request, the Request is analyzed, retrieval matching is carried out in an interface conversion configuration table, a matched preset conversion interface is determined, the original Request is suspended to wait, and a new Request is transmitted to the server side by using the obtained preset conversion interface.

The server side outputs the request response result to the proxy service, the proxy service carries out reduction processing according to the original request API interface, and the response result after the reduction processing is issued to the client side.

It should be noted that, by acquiring data by the method provided above, a user does not need to update the version, that is, service data supported by the latest interface can be also obtained by an API request of an old version, so that user experience is enhanced, and the problem that new service data must be updated for acquiring new service data is solved.

In addition, the above process is directly skipped to enable the original request to be normally initiated to the server side without any conversion processing aiming at the condition that the preset conversion interface is not matched. The server side responds to the original request and directly sends a response result to the client side.

Aiming at different types of service requests, in the matching process, the URL and the request method of the request must simultaneously meet the standard rule which is completely the same as the preset URL and the preset request method, namely when the standard rule is met, the preset conversion interface can be determined to be converted, otherwise, the corresponding process is executed according to the original request.

In addition, aiming at other service requests, other key attributes of the requests, one or more of message headers, URL parameters and message bodies can be obtained; and when one or more conditions that the requested message header is matched with the preset message header, the URL parameter is matched with the preset URL parameter or the message body is matched with the preset message body are met, determining the preset conversion interface. It should be noted that, if the other key attributes are set, the conversion interface is determined to be preset when the key attributes are completely matched, otherwise, the corresponding process is executed according to the original request.

Referring to the structural block diagram of the configuration system shown in fig. 2, an embodiment of the present invention further provides an interface matching system, including: the system comprises a client, a proxy service and a server;

the client is used for initiating a request;

the proxy service comprises an attribute analysis module, an analysis module and a restoration module,

the attribute analysis module is used for intercepting a request initiated by a client and analyzing request attributes, wherein the request attributes comprise a Uniform Resource Locator (URL), a request method and one or more of a message header, a URL parameter and a message body;

the analysis module is used for analyzing whether the request attribute is matched with a preset request attribute, determining a preset conversion interface when the request attribute is matched with the preset request attribute, suspending the original request for waiting, and sending the original request to the server if the original request is not matched with the preset conversion interface, wherein the preset request attribute comprises a preset URL (uniform resource locator), a preset request method and one or more of a preset message header, a preset URL parameter and a preset message body;

the restoration module is used for restoring the request response result output by the server according to the original request API interface and sending the response result after restoration to the client;

and the server is used for outputting a response result according to the request, wherein when the received request is a new request, the response result is output to the restoration module, and when the received request is an original request, the response result is directly issued to the client.

In summary, 1) the configuration method of the present invention has low requirements on encoding capability, and other personnel except developers can easily perform interface information configuration, thereby maximizing extensibility; 2) the user does not need to update the version, and can also obtain the service data which is only supported by the latest interface through the API request of the old version, so that the user experience is enhanced; 3) on the system architecture separated from the front end and the back end, the constraint of version consistency is separated again, particularly, the seamless conversion is realized in the using process depending on the third party audit or the program which cannot be automatically updated by the client, so that the version iteration has no compatible burden of an interface.

The above is only a preferred embodiment of the present invention, and is not intended to limit the present invention, and various modifications and changes will occur to those skilled in the art. Any modification, equivalent replacement, or improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

完整详细技术资料下载
上一篇:石墨接头机器人自动装卡簧、装栓机
下一篇:进程管理方法、装置和电子设备

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!