Disclosure of Invention
The technical task of the present invention is to provide a method for implementing API gateway interface arrangement based on configuration, which can obtain corresponding data functions of a plurality of backend service interfaces through one-time interface call.
In order to achieve the purpose, the invention provides the following technical scheme:
a method for realizing API gateway interface arrangement based on configuration specifically comprises the following steps:
s1, compiling, arranging and configuring;
s2, analyzing the configuration in the step S1;
s3, executing the task arranging step;
and S4, assembling the response result.
Preferably, in step S1, the interface is arranged using a json code format, and the task step is included in an array.
Preferably, the json encoding format comprises the following elements:
step, namely a task step;
inputs are the entries of the editing step;
outputs are the return of the orchestration step.
Preferably, in step S2, the json configuration is parsed into a processable data format according to the programming language.
Preferably, in step S3, the task steps are saved in an array, and the handler traverses the array and performs responsive processing according to the task step type of each step.
Preferably, the types supported by the task step include: http type, response type, if type, series type, and parallel type.
Preferably, the task step is an http type, and in order to initiate a request to an upstream, configuration includes type, that is, a request type, name, method, that is, an http request mode, inputs, that is, an http request parameter definition, url, that is, an http request address, and timeout, that is, an http request timeout.
Preferably, the task step is of response type, and is used for defining the result returned by the orchestration, and includes the following elements: type is the type, name is the name, outputs are the format and fields used to define the layout return result.
Preferably, the task step is of an if type, and is used for judging a flow result, and executing a different flow according to the result.
Preferably, the task step is a series type, and the task step comprises a subtask step, and the subtasks are executed in series; and if the task step is of a parallel type, the task step comprises a subtask step, and the subtasks are executed in parallel.
The layout configuration of the method for realizing the layout of the API gateway interface based on the configuration is compiled by using a json coding format, wherein the concept of the layout step is defined, and the layout steps are of various types, including http which is used for initiating an http request; if is to make branch condition judgment; series is a plurality of serial steps nested; parallel is nesting a plurality of parallel steps; response is the assembly response result. A plurality of arrangement steps are stored in the json array, and when the program is executed, the array containing the arrangement steps is traversed, and corresponding functions are executed according to the type of the arrangement steps.
Compared with the prior art, the method for realizing the arrangement of the API gateway interface based on the configuration has the following outstanding beneficial effects:
the method for realizing the arrangement of the API gateway interface based on the configuration can arrange a plurality of interfaces, thereby obtaining the function of responding data of a plurality of back-end service interfaces through one-time interface calling;
the capability of serial execution of a plurality of back-end service interfaces is realized, namely, the next interface call is executed only if the previous interface call is successful;
and (III) the capability of parallel execution of a plurality of back-end service interfaces is realized, namely the back-end service interfaces are executed simultaneously without mutual dependence, the response time of calling the API interface by a user is reduced, and the method has good popularization and application values.
Detailed Description
The method for implementing API gateway interface orchestration based on configuration according to the present invention will be described in further detail with reference to the accompanying drawings and embodiments.
Examples
As shown in fig. 1, the method for implementing API gateway interface arrangement based on configuration of the present invention specifically includes the following steps:
and S1, writing the layout configuration.
The interface is arranged using a json code format, and the task steps are contained in an array. The json encoding format includes the following elements: step, namely a task step; inputs are the entries of the editing step; outputs are the return of the orchestration step.
S2, analyzing the configuration in the step S1. The json configuration is parsed into a processable data format according to a programming language.
And S3, executing the programmed task step. The task steps are stored in an array, the processing program traverses the array, and the response processing is executed according to the task step type of each step.
And S4, assembling the response result.
The types of task step support include: http type, response type, if type, series type, and parallel type.
The task step is of an http type, and a request for upstream is initiated, and the configuration comprises type, namely a request type, name, method, namely an http request mode, inputs, namely http request parameter definition, url, namely an http request address, and timeout, namely http request timeout.
Examples are:
the task step is of a response type, and is used for defining the result returned by the layout, and comprises the following elements: type is the type, name is the name, outputs are the format and fields used to define the layout return result.
Examples are as follows:
if the task step is of the if type, the task step is used for judging the process result and executing different processes according to the result. Examples are as follows:
and if the task step is a series type, the task step comprises a subtask step, and the subtasks are executed in series. Examples are as follows:
and if the task step is a parallel type, the task step comprises a subtask step, and the subtasks are executed in parallel.
Examples are as follows:
the layout configuration of the method for realizing the layout of the API gateway interface based on the configuration is compiled by using a json coding format, wherein the concept of the layout step is defined, and the layout steps are of various types, including http which is used for initiating an http request; if is to make branch condition judgment; series is a plurality of serial steps nested; parallel is nesting a plurality of parallel steps; response is the assembly response result. A plurality of arrangement steps are stored in the json array, and when the program is executed, the array containing the arrangement steps is traversed, and corresponding functions are executed according to the type of the arrangement steps.
The above-described embodiments are merely preferred embodiments of the present invention, and general changes and substitutions by those skilled in the art within the technical scope of the present invention are included in the protection scope of the present invention.