Data conversion method and conversion system of API (Application Program Interface) and configuration method of proxy interface

By generating structure trees and mapping configurations, the two-way conversion of API data is realized, which solves the problem of low flexibility in API data conversion, improves efficiency and adaptability, and reduces integration costs.

CN118963830APending Publication Date: 2024-11-15四川启睿克科技有限公司
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202410996876.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-24
Publication Date
2024-11-15

AI Technical Summary

Technical Problem

The existing API data conversion methods are relatively low in flexibility, making it difficult to deal with the problem of inconsistent complex data structures and structures, resulting in complex configuration and high cost.

Method used

By analyzing source data and target data to generate structure trees, establish mapping relationships, generate mapping configurations, implement bidirectional conversion between source data and target data, support the transformation of nested arrays and hierarchical structures, reducing configuration complexity and development costs.

Benefits of technology

It improves the flexibility and efficiency of API data conversion, reduces project integration costs, supports rapid docking and adaptation between different systems, avoids repeated hard coding, and realizes automatic conversion of complex data structures.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118963830A_ABST
    Figure CN118963830A_ABST
Patent Text Reader

Abstract

The invention discloses a data conversion method and a data conversion system of an API (Application Program Interface) and a configuration method of an agent interface, belongs to the technical field of application programming (API), and is used for solving the problem that the current internet general data conversion method cannot effectively convert between source data and target data structures with huge differences such as SOAP (Simple Object Application Protocol) and Restful. According to the method, the corresponding structure trees are generated after the source data and the target data are analyzed and structured, the mapping relation between the data and the structure trees and the mapping relation between the structure trees are established, and mapping configuration is carried out; along with calling of an API interface and driving of data conversion, data conversion can be completed through mapping configuration only by inputting and outputting example data such as source data and target data, rapid butt joint of different service systems is supported more flexibly, meanwhile, the method can be used as an API gateway to complete data conversion without changing the source interface or changing the target interface. Configuration of the proxy interface and simulation or real calling of the interface are achieved, extra development is not needed, the project integration cost is reduced, and the project integration docking efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of application programming interface, in particular to an API data conversion method, a conversion system and a configuration method for an agent interface. Background Art

[0002] API stands for Application Programming Interface, which is a technology that allows applications or systems to communicate and exchange data with each other. By configuring the corresponding API, different applications or systems can interact with each other and call each other. For example, Facebook's server configures API, and developers can read or write user data and tweets to the server through the user end; for another example, the server of an e-commerce platform configures API, and third-party applications can access and edit the product list, price list and inventory data of the e-commerce platform through API.

[0003] API data exchange relies on API data structure conversion. Due to the exchange or call of data between different applications, it is necessary to configure the corresponding API conversion system. The main research directions of API data conversion include two aspects: one is to improve the flexibility and configurability of the conversion system; the other is how to complete the conversion of complex API data structures, such as the conversion of nested arrays and nested JSON hierarchical data structures. The current research on API data conversion has the following main defects: First, due to the complete use of hard-coded methods, simple source data is processed one by one by function, field name changes, type conversion, and default values ​​are configured, the configuration flexibility is low, and the configuration is more cumbersome; second, a relatively simple low-code API interface configuration or API gateway configuration is used, which only refers to the structure of the source data for configuration. The generated target data is similar to the source data and is difficult to convert into the required target data.

[0004] For example, the Chinese patent with patent number CN117850766A extracts the data model elements of the source data, converts and generates predefined interfaces and SQL templates according to the updated page interface and SQL statements, and then converts the data format of the page interface into the format required for low-code expression by configuring the conversion system of the predefined interface and SQL template. This solution can only complete data conversion between data structures with the same structure, and the configuration flexibility is low; and the configuration of the predefined interface data needs to refer to each node of the page interface data for configuration, which makes the work of developers to configure the conversion system cumbersome and complicated; for example, the Chinese patent with patent number CN111385292B converts the field set of the source data into a descriptor mapping relationship function, and according to the description of the descriptor, calls the corresponding mapping function to complete the interaction between the protocol message and the data parameters. It can only convert hard-coded fixed-format data, and cannot realize the conversion of complex arrays or extended data. Summary of the invention

[0005] The purpose of the present invention is to provide an API data conversion method, a conversion system and a configuration method for a proxy interface, which are used to solve the problem that the API data conversion in the prior art can only perform function processing, field name change, type conversion, and default value configuration on simple source data one by one, or only configure with reference to the structure of the source data, and is difficult to convert into the required target data, resulting in low flexibility and weak configurability of API data conversion.

[0006] The present invention solves the above problems through the following technical solutions:

[0007] A data conversion method for an API, comprising the following steps:

[0008] S1: Acquire source data from the user end; transmit the source data to the server end, parse the data structure of the source data according to the first mapping relationship, and then convert the source data into a source structure tree; acquire first target data from the user end; transmit the first target data to the server end, parse the first target data according to the second mapping relationship, and then convert the first target data into a target structure tree;

[0009] S2: establishing a third mapping relationship between the source structure tree and the target structure tree, and generating a mapping configuration, wherein the mapping configuration includes: the source structure tree, the target structure tree and the third mapping relationship;

[0010] S3: If the user terminal inputs request data, the server terminal can convert the request data into second target data matching the user terminal or the third service according to the mapping configuration.

[0011] The data conversion method of the API provided by the present invention can obtain a source structure tree by parsing the source data according to the first mapping relationship, and can obtain a target structure tree by parsing the first target data according to the second mapping relationship. It not only parses and obtains the data structure of the source data, but also parses and obtains the data structure of the target data, establishes a third mapping relationship between the source structure tree and the target structure tree, and the configured third mapping relationship is a mapping between the source structure tree and the target structure tree, and then generates a mapping configuration including the source structure tree, the target structure tree and the third mapping relationship. The request data input by the user end is converted into the target data through the mapping configuration, and there is no need to convert the request data into a data model, and then the data model or descriptor is associated with each data node of the target data. Configuration is performed, thereby reducing the amount of configured data and improving configuration efficiency; and, a source structure tree is obtained through source data, and a target structure tree is obtained through the first target data, and in accordance with the data structure of the source data or the target data, if the source data or the target data is expanded, updated, or the array level changes, a matching source structure tree or a target structure tree can be obtained, and then a matching mapping configuration can be generated and configured, making the configuration more flexible to respond to data changes; that is, only by inputting and outputting sample data, three conversions between source data and target data can be achieved, which improves the flexibility and ease of control of the configuration, and then the automatic conversion of API data can be automatically completed, thereby reducing the development cost of API during project integration and improving the integration speed.

[0012] In order to solve the problems that data protocol information cannot be automatically extracted and generated according to source data, the target data structure cannot be flexibly configured, and complex protocol configuration and conversion cannot be completed quickly and scalably, and the source data and target data structures with huge differences such as SOAP and RESTful cannot be effectively converted into each other, the present invention further improves the data conversion method of the API, wherein the source structure tree includes: a first array type, a first number of arrays, a first nested node and a first hierarchical relationship; the target structure tree includes: a second array type, a second number of arrays, a second nested node and a second hierarchical relationship.

[0013] As an improved solution of the present invention, the source structure tree and the target structure tree obtained after parsing both contain array type, array number, nested nodes and hierarchical relationship information. The third mapping relationship established between the source structure tree and the target structure tree enables the same array level fields between the source structure tree and the target structure tree to be cross-moved, and the structure tree of the nested array structure can increase or decrease the data dictionary level, so that complex data containing nested array structures and nested hierarchical structures can be converted; and further, when different systems or different versions are docked or adapted for compatibility, for data with inconsistent structures, different contents or different upstream and downstream structures, conversion can be achieved without repeated hard coding, annotation or adding entity data classes, supporting the rapid docking of API structure data of different business systems, and further improving the flexibility and conversion capability of API data conversion.

[0014] A further improvement of the data conversion method of the API of the present invention, the implementation of the mapping configuration includes the following steps: establishing a third mapping relationship between the source structure tree and the target structure tree, so that the hierarchical fields of the same array of the source structure tree and the target structure tree are cross-moved, and the data dictionary level is increased or decreased in the layer nested array structure of the source structure tree and the target structure tree, thereby being able to convert complex data containing nested array structures and nested hierarchical structures.

[0015] As a further improvement of the present invention, conversion is performed for complex data structure models. For example, if the array hierarchy structure changes, the source data of the upper and lower array structures can be converted into a target array with another layer of data dictionary level nested between them. Alternatively, the dictionary data in the array can be cross-moved with the dictionary primary keys in other arrays of the same level, so that the same array hierarchy fields between standard data structures can be cross-moved and Map dictionary layers can be added or subtracted in multi-layer nested array structures. Finally, the standard data structure composed of the source structure tree and the target structure tree is converted into the required target data. This can achieve different systems or different versions of the same system when docking or adapting and being compatible, with inconsistent data structures, different data contents or different upstream and downstream data structures, such as data docking in SOAP and Restful data formats.

[0016] A further improvement of the API data conversion method of the present invention, wherein S2 further comprises the following steps:

[0017] S21: generating a structure tree converter from the mapping configuration, wherein the structure tree converter traverses the source structure tree;

[0018] S22: querying the data value of the node name in the source structure tree in the source data through the original level information attached to the location information of the source structure tree;

[0019] S23: Processing the data value through the source data function, and initializing or assigning the processed data value to the target structure tree; when the original level information contains an array type data structure, the structure tree converter records the array level and traverses the index value.

[0020] As a further improvement of the present invention, by configuring the mapping in the conversion module to generate a structure tree converter, the structure tree converter can traverse the source structure tree, for example, traverse the XML Document structure or the JSON Map data structure, and realize three conversions. Then, through steps S21 to S23, when the original hierarchical information contains an array type data structure, the structure tree converter records the array hierarchy and traverses the index value, thereby avoiding the problem of repeated traversal of the array when the same field is traversed next time, further reducing repeated operations of data conversion, saving computing energy, and improving conversion efficiency.

[0021] A further improvement of the data conversion method of the API further includes the following steps:

[0022] S4: According to the mapping configuration, convert the source data into third target data, and verify whether the field type of the third target data is consistent with / inconsistent with the field type of the first target data; the verification items include at least one of direct mapping, field function processing, and array mapping layer correspondence.

[0023] S5: If the field type of the third target data is consistent with the field type of the first target data, the verification result is verification passed;

[0024] S6: Save into the warehouse, save the source data, the first target data, the third target data and the mapping configuration into the warehouse;

[0025] S7: The verification result and the mapping configuration are transmitted to the user end, and the user end responds and saves the mapping configuration and the verification result.

[0026] As a further improvement of the present invention, through steps S4-S7, the mapping configuration can be verified on the server side, and then the accuracy of the mapping configuration obtained according to the source data and the target data can be verified, so that the configuration can be improved in time or the verification result saved in response to the verification can be saved, so as to further improve the accuracy and matching of API data conversion.

[0027] To achieve the purpose of the present invention, in order to implement the above API data conversion method, the present invention also provides an API data conversion system, including: a parsing module, a mapping module, a conversion module, a generation module and a calling module;

[0028] The parsing module is used to parse the source data and the target data, and define the source structure tree and the target structure tree;

[0029] The mapping module is used to establish the first mapping relationship, the second mapping relationship and the third mapping relationship, and generate a mapping configuration;

[0030] The conversion module is used to realize the bidirectional conversion between source data and source structure tree, the bidirectional conversion between target data and target structure tree, and the conversion between source structure tree and target structure tree;

[0031] The generating module is used to generate a conversion interface according to the mapping configuration, and cooperate with the calling module to verify the mapping configuration;

[0032] The calling module is used to call the conversion interface or the proxy interface.

[0033] The data conversion system of the API of the present invention automatically extracts and converts the source data instance and the target data instance into the source structure tree and the target structure tree respectively by setting the parsing module and the conversion module, and then establishes the first, second and third mapping relationships through the mapping module. The parsing module, the conversion module and the mapping module cooperate with each other to complete the conversion of the source structure tree and the target structure tree. Then, the mapping configuration is generated into a conversion interface matching the source data and the target data by the generation module, the mapping module and the conversion module, so as to form an API conversion system capable of converting complex data including nested array structures and nested hierarchical structures, thereby solving the problem of docking or interoperability between different systems or systems of different versions. When adapting and being compatible, the system needs to repeatedly hard-code, annotate or add entity data to achieve data docking due to inconsistent data structures, different data contents or different upstream and downstream data structures; it fundamentally optimizes the defects of the existing low-code API and the existing simple protocol configuration method; it only needs to give the input and output sample data structures to complete the data structure conversion, and more flexibly supports the rapid docking of API data between different business systems; at the same time, the source interface of the API gateway can be kept unchanged, and the configuration of the conversion system can be completed to complete the configuration of the required proxy interface without the need for additional development, thereby reducing project integration costs and improving project integration docking efficiency.

[0034] To achieve the purpose of the present invention, based on the above API conversion system, a conversion call including a third-party service is realized. The present invention also provides a configuration method of an API proxy interface, comprising the following steps:

[0035] P1: Configure the first proxy interface on the user side and configure the third-party interface that needs to be called;

[0036] P2: Select source data, parse the first mapping configuration of the first proxy interface, the first mapping configuration including: request body mapping configuration or response body mapping configuration; input simulation data, send the simulation data to the server, and call the first mapping configuration of the server;

[0037] P3: The server converts the simulation data into request data according to the called first mapping configuration; the server sends a simulation request to the third-party service; the third-party service responds to the third-party interface and returns response data to the server; the server converts the response data into a response structure tree according to the first mapping configuration, and transmits the response structure tree to the user end;

[0038] P4: The user end receives the response structure tree and confirms whether or not to generate the second proxy interface; if the second proxy interface needs to be generated, the user end saves the response structure tree and the second mapping configuration, wherein the second mapping configuration includes the response structure tree;

[0039] P5: The server saves data into the database;

[0040] P6: The server generates a second proxy interface, and transmits data of the second proxy interface back to the user end for the user end to call.

[0041] The configuration method of the API proxy interface described in the present invention can complete the simulation and real call of the API interface through the API interface configuration, that is, the data conversion of the API interface can be completed only through simple configuration without the need for additional development, thereby reducing project integration costs and improving project integration docking efficiency.

[0042] Compared with the prior art, the present invention has the following advantages and beneficial effects:

[0043] (1) The data conversion method of the API can quickly and accurately convert the request data input by the user end into the target data through three conversions of the mapping configuration, without converting the request data into a data model and then configuring the data model or descriptor with each data node of the target data, thereby reducing the amount of configured data and improving the efficiency of configuration; if the source data or the target data is expanded, updated or the array level changes, a matching mapping configuration can be generated and configured, so that the configuration can more flexibly respond to data changes;

[0044] (2) The data conversion method of the API can realize three conversions between source data and target data by only inputting and outputting sample data, thereby improving the flexibility and ease of configuration, and then automatically completing the data conversion of the API, thereby reducing the development cost of the API during the project integration process and improving the integration speed;

[0045] (3) The API data conversion system forms an API conversion system that can convert complex data including nested array structures and nested hierarchical structures, and can solve the problem that when different systems or different versions of systems are connected or adapted and compatible, the system needs to repeatedly hard code, annotate or add entity data to achieve data connection due to inconsistent data structures, different data contents or different upstream and downstream data structures;

[0046] (4) The data conversion system of the API fundamentally optimizes the defects of the existing low-code API and the existing simple protocol configuration method; it only needs to provide the input and output sample data structures to complete the data structure conversion, and more flexibly supports the rapid data connection of APIs between different business systems; and, the source interface of the API gateway can be kept unchanged, and after the conversion system is configured, the required proxy interface can be configured, without the need for additional development, thereby reducing the project integration cost and improving the efficiency of project integration connection;

[0047] (5) The configuration method of the API proxy interface can complete the simulation and real call of the API data conversion system. Only through simple configuration, the API data conversion can be completed without additional development. It can generate configurations including but not limited to proxy interfaces that support third-party services, thereby reducing project integration costs and improving project integration docking efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0048] Figure 1 This is a flow chart of the data conversion method of the API of the present invention;

[0049] Figure 2 This is a schematic diagram of the module structure of the API data conversion system of the present invention;

[0050] Figure 3 A flowchart of a method for configuring a proxy interface of an API according to the present invention. DETAILED DESCRIPTION

[0051] The present invention is further described in detail below in conjunction with examples, but the embodiments of the present invention are not limited thereto.

[0052] Example 1

[0053] refer to Figure 1 As shown, this embodiment discloses an API data conversion method, comprising the following steps:

[0054] S1: Acquire source data from the user end; transmit the source data to the server end, parse the data structure of the source data according to the first mapping relationship, and then convert the source data into a source structure tree; acquire first target data from the user end; transmit the first target data to the server end, parse the first target data according to the second mapping relationship, and then convert the first target data into a target structure tree;

[0055] S2: establishing a third mapping relationship between the source structure tree and the target structure tree, and generating a mapping configuration, the mapping configuration including: the source structure tree, the target structure tree and the third mapping relationship;

[0056] S3: If the user terminal inputs request data, the server terminal can convert the request data into second target data matching the user terminal or the third service according to the mapping configuration.

[0057] It should be noted that the source data can be entered manually through text import, and the supported data formats include but are not limited to json data and xml formatted data. It should be noted that the xml extensible data exchange format is used for configuration files, document storage, data exchange, and json data is understood as JavaScript object notation, which is used for data exchange between web applications.

[0058] Specifically, the mapping configuration generated by the data conversion method of the API of the present invention is understood as follows: the mapping configuration includes an API standard structure tree, which is an intermediate layer between the source data and the target data. The mapping configuration can be realized by establishing a mapping relationship of three conversions between the source data A and the target data T; in fact, the source structure tree SA is obtained through the source data A, and the second mapping relationship STM between the target data T and the structure standard structure tree ST is generated through the mapping configuration, so that not only the structure conversion of the source data but also the structure conversion of the target data and the conversion between the source structure tree and the target structure tree are realized; wherein SA and ST are unidirectionally converted through STM, and A and SA, T and ST are bidirectionally converted through the system module, that is, data structure is extracted and reversely converted, so as to realize three conversions, such as source data-source structure tree-first target data-first target structure tree-mapping configuration-second target data, so as to realize the conversion of the request data into the second target data matching the user end or the third service; the mapping relationship STM is understood as a mechanism for linking the physical memory address with the internal address space of the processor, and when the program is running, it can be accessed through memory mapping, wherein A, SA, T, ST and AT are all letter marks for the convenience of description of the present invention, and no substantial meaning is explained.

[0059] It should be noted that the first target data is understood as the target data used to generate the mapping configuration input, and the second target data is understood as the target data converted from the source data to verify, configure or call the mapping configuration. For the convenience of distinction, they are marked as the first and second. The first, second and third are not substantially explained in the present invention.

[0060] In the described S1, the service end receives the sample data of the source data entered by the user end, and parses it, and extracts the source structure tree according to the data format of the sample data. The characteristics of the source structure tree include information such as node name (name), node data type (type), node location (location), node attribute identifier (attr), number of node path arrays (arrays), and nested nodes (nodeList); wherein the node data type includes basic data types (char, short, double, short, float, int, long, bool, byte, string), array type (array) and dictionary type (dict). When extracting, it is also necessary to extract the corresponding data type in the structure tree according to the data type in the source data structure. When generating the node location (location), the location information in the source data structure is determined by the positioning symbol "." + field name, such as: [{"item":"1","name":"lcd","intList":[5,5,4]}].

[0061] The source structure tree or target structure tree obtained based on the source data and target data is as follows:

[0062]

[0063]

[0064]

[0065] Specifically, in the data conversion method of the API described in the present invention, the source structure tree includes: a first array type, a first number of arrays, a first nested node and a first hierarchical relationship; the target structure tree includes: a second array type, a second number of arrays, a second nested node and a second hierarchical relationship.

[0066] It should be noted that the hierarchical relationship in the source structure tree or the target structure tree is maintained in the nodeList node data. The location value ".item" is split by the positioning symbol ".". If the first-level positioning name generated after the split is empty, it means that the first level is an array, and the second-level item is the field of the dictionary structure inside the array; for example: {"item":"1","info":{"name":"lcd","age":16},"orgList":[{"org":"Organization 1","address":"Feiyun Avenue, xx City"},{"org":"Organization 2","address":"Zhongshan Avenue, xx City"}]}, after parsing, the converted extracted source structure tree or target structure tree is:

[0067]

[0068]

[0069]

[0070] The location value "info.name" has a data type of string, info is a field in the dictionary structure, its value is dictionary data, name is a field in the info dictionary data, "orgList..org" has a data type of string, orgList is a field in the dictionary data, and its value is an array type (after the ".." is separated by the separator ".", there is a space, indicating that there is a layer of array structure). The internal data type of the array is dictionary data, org is a field in the dictionary data, and its value data type is string. That is, the structured data itself is a nested dictionary data structure.

[0071] In this embodiment, an associated mapping relationship between the source structure tree and the target structure tree is established in S2, that is, a third mapping relationship is established. The implementation of the mapping configuration includes the following steps: establishing a third mapping relationship between the source structure tree and the target structure tree, so that the hierarchical fields of the same array of the source structure tree and the target structure tree are cross-moved, and the data dictionary level is increased or decreased in the layer nested array structure of the source structure tree and the target structure tree, so as to convert complex data containing nested array structures and nested hierarchical structures. For example, updating the field name, configuring function processing of the data value, etc., submitting the mapping relationship between the source data, the target data and the configuration, such as:

[0072]

[0073]

[0074]

[0075] Among them, the key in the key-value pair of the mapping configuration dictionary data structure is the location value in the API data structure, and there is a correspondence. Its value is a configuration dictionary structure, including but not limited to the mapping target location value (mapping), a pre-processing function set (prePost), and a post-processing function set (post). The pre-processing function will be called before conversion to the target field, and the post-processing function set will be called after conversion to the target field.

[0076] Specifically, in this embodiment, S2 further includes the following steps:

[0077] S21: Generate a structure tree converter from the mapping configuration, and the structure tree converter traverses the source structure tree; S22: Query the data value of the node name in the source structure tree in the source data through the original hierarchy information attached to the location information of the source structure tree; S23: Process the data value through the source data function, and initialize or assign the processed data value to the target structure tree; when the original hierarchy information contains an array type data structure, the structure tree converter records the array hierarchy and traverses the index value.

[0078] Specifically, the API data conversion method further includes the following steps:

[0079] S4: According to the mapping configuration, the source data is converted into the third target data, and the field type of the third target data is verified to be consistent / inconsistent with the field type of the first target data; the verification items include at least one of direct mapping, field function processing, and array mapping layer correspondence. S5: If the field type of the third target data is consistent with the field type of the first target data, the verification result is verification passed; S6: Save into the database, and save the source data, the first target data, the third target data and the mapping configuration into the database; S7: Transmit the verification result and the mapping configuration to the user end, and the user end responds and saves the mapping configuration and the verification result.

[0080] It should be noted that the verification items include but are not limited to direct mapping, field function processing, and array mapping layer correspondence, wherein the array mapping layer correspondence is understood as: if the field of the source data passes through N layers of arrays, then the field of the target data generated according to the mapping configuration must pass through N layers of arrays, but there is no continuity requirement, such as two consecutive layers of array fields can be mapped to spaced target data structures.

[0081] Example 2

[0082] The present invention also provides an API data conversion system, which can implement the API data conversion method. Figure 2As shown, it includes: a parsing module, a mapping module, a conversion module, a generation module and a calling module; the parsing module is used to parse the source data and the target data, and define the source structure tree and the target structure tree; the mapping module is used to establish the first mapping relationship, the second mapping relationship and the third mapping relationship, and generate the mapping configuration; the conversion module is used to realize the bidirectional conversion of the source data and the source structure tree, the bidirectional conversion of the target data and the target structure tree, and the conversion of the source structure tree into the target structure tree; the generation module is used to generate the conversion interface according to the mapping configuration, and cooperate with the calling module to verify the mapping configuration; the calling module is used to call the conversion interface or the proxy interface.

[0083] In this embodiment, the parsing module can block define the API source structure tree, and can parse structured data of different types such as json type or xml type through reflection, extract structured data from the instance data structure, and generate an API structure tree. The API structure tree and the source data structure can complete bidirectional conversion.

[0084] The mapping module generates a source structure tree and a target structure tree after configuring and inputting source data and target data and calling the parsing module of the API structure tree; the source structure tree field mapping is selected by the user end, and the target structure tree field is associated, and additional target structure tree fields, source and target data processing functions, target data function processing, and default values, ignored values, etc. are set for additional attributes to complete the mapping configuration of all target structure trees. In this embodiment, for example, the data configuration module requires the user to confirm the source structure tree and the target structure tree, and the source structure tree and the target structure tree need to be mapped and configured, such as mapping nodes in the source structure tree to nodes of the same level or different levels in the target structure tree. When mapping configuration is performed, data type determination will be performed, and different data types will not be allowed to be mapped, but the same data type can be guaranteed by built-in functions; when the mapping configuration is stored in the warehouse, the API structure tree parsing module will perform pre-storage analysis, and at the same time verify the built-in function configuration, and the configuration that meets the design can be stored in the warehouse.

[0085] In this embodiment, the conversion module generates a converter through a mapping configuration. The converter first traverses the source structure tree, such as the XML Document structure or the JSON Map data structure, and quickly queries the data value of the node name in the source structure tree in the source data through the original hierarchical information attached to the structure tree location information. The source data function is processed and initialized or assigned to the target structure data to complete the data conversion. When the hierarchical information has an array type structure, the conversion module records the array hierarchical traversal index value to avoid the problem of repeated traversal of the array when the same field is traversed next time.

[0086] Among them, data conversion mainly occurs in three conversions, namely source data-source data structure tree-target structure tree-target data, as follows:

[0087] The first conversion: read or automatically extract the structure A of the source data into the source structure tree SA; the second conversion: convert the source structure tree SA into the target structure tree TA according to the mapping configuration STM; the third conversion: automatically convert the target structure tree TA into the new target data T; that is, the structure A of the source data or the structure T of the target data are bidirectionally converted with the structure tree.

[0088] In this embodiment, the generation module selects a mapping configuration through the user, and sets the required URI, request method, request parameters, data encryption and decryption methods, authentication parameters, etc. The system generates a conversion interface through the relevant mapping configuration and associates the conversion interface with the mapping configuration. The generation module can also simulate the request of the conversion interface by configuring the calling module to verify whether the relevant data results meet the design. At the same time, the generated conversion interface can be published and removed from the shelves; to ensure the security and reliability of the conversion interface, the editing / deletion mapping operation can be controlled through additional business processes; it should be noted that the URI is understood as a uniform resource identifier string, which is a string used to identify resources on the Internet. It is used to identify resources, but not necessarily point to the specific location of the resource. It is used to name or identify resources, and does not necessarily provide a method to access the resource.

[0089] In this embodiment, the calling module supports calling the external proxy interface, the system preloads the mapping configuration, generates a converter, searches the mapping configuration, converts the source data into request data that meets the specification requirements according to the source structure tree, calls the system to generate the conversion interface or configures the proxy interface, converts the target data according to the mapping configuration, and finally returns it to the user or the client; wherein there are three main steps when the API is called: the first step: reading the source data structure A and automatically extracting it as the source structure tree SA; the second step: according to the called proxy interface, obtaining the corresponding mapping configuration STM, and converting the source structure tree SA into the target structure tree TA; the third step: converting the target structure tree TA into the target data T.

[0090] Example 3

[0091] On the basis of Example 1 and Example 2, in order to realize the generation or calling of a proxy interface including but not limited to a third-party service, this embodiment provides a configuration method of an API proxy interface, including the following steps:

[0092] P1: Configure the first proxy interface on the user side and configure the third-party interface that needs to be called;

[0093] P2: Select source data, parse the first mapping configuration of the first proxy interface, the first mapping configuration including: request body mapping configuration or response body mapping configuration; input simulation data, send the simulation data to the server, and call the first mapping configuration of the server;

[0094] P3: The server converts the simulation data into request data according to the called first mapping configuration; the server sends a simulation request to the third-party service; the third-party service responds to the third-party interface and returns the response data to the server; the server converts the response data into a response structure tree according to the first mapping configuration, and transmits the response structure tree to the user;

[0095] P4: The user end receives the response structure tree and confirms whether or not to generate the second proxy interface; if the second proxy interface needs to be generated, the user end saves the response structure tree and the second mapping configuration, and the second mapping configuration includes the response structure tree;

[0096] P5: The server saves data into the database;

[0097] P6: The server generates a second proxy interface and transmits the data of the second proxy interface back to the user end for the user end to call.

[0098] It should be noted that the first mapping configuration is understood as a mapping configuration generated by the user end and the server end that can interact and realize data conversion, and the second mapping configuration is understood as a mapping configuration formed with reference to the structure of the target data of the third-party service; the first proxy interface is understood as a proxy interface before the second mapping configuration is configured, and is also understood as a traditional proxy interface that is not configured with the second mapping configuration; the second proxy interface is understood as a new proxy interface generated after the second mapping configuration, which can realize the proxy interface called by the client.

[0099] In this embodiment, the simulation data is understood as json or xml simulation data with complete input interface, and the conversion of simulation data into request data is understood as: for example, updating field hierarchy, updating field name, updating field type and other related structural information; the response data is converted into a response structure tree. Similar to the request body, the response body can also perform data structure conversion, such as json to json, json to xml, xml to json. Similarly, the field name, field type, and field value in the structure can be converted accordingly according to the API conversion configuration, and finally returned to the user end for display.

[0100] Although the present invention is described herein with reference to the illustrative embodiments of the present invention, the above embodiments are only preferred embodiments of the present invention, and the embodiments of the present invention are not limited to the above embodiments. It should be understood that those skilled in the art can design many other modifications and embodiments, which will fall within the scope and spirit of the principles disclosed in this application.

Claims

1. A data conversion method for API, It is characterized in that The following steps are involved: S1: Acquire source data from the user end; transmit the source data to the server end, parse the data structure of the source data according to the first mapping relationship, and then convert the source data into a source structure tree; acquire first target data from the user end; The first target data is transmitted to the server, and the first target data is parsed according to the second mapping relationship, and then the first target data is converted into a target structure tree; S2: establishing a third mapping relationship between the source structure tree and the target structure tree, and generating a mapping configuration, wherein the mapping configuration includes: the source structure tree, the target structure tree and the third mapping relationship; S3: If the user terminal inputs request data, the server terminal can convert the request data into second target data matching the user terminal or the third service according to the mapping configuration.

2. The API data conversion method according to claim 1, It is characterized in that The source structure tree includes: a first array type, a first number of arrays, a first nested node and a first hierarchical relationship; the target structure tree includes: a second array type, a second number of arrays, a second nested node and a second hierarchical relationship.

3. The API data conversion method according to claim 2, It is characterized in that The implementation of the mapping configuration includes the following steps: establishing a third mapping relationship between the source structure tree and the target structure tree, so that the hierarchical fields of the same array of the source structure tree and the target structure tree are cross-moved, and increasing or decreasing the data dictionary level in the layer nested array structure of the source structure tree and the target structure tree, thereby being able to convert complex data containing nested array structures and nested hierarchical structures.

4. The API data conversion method according to claim 2, It is characterized in that The S2 further comprises the following steps: S21: generating a structure tree converter from the mapping configuration, wherein the structure tree converter traverses the source structure tree; S22: querying the data value of the node name in the source structure tree in the source data through the original level information attached to the location information of the source structure tree; S23: Processing the data value through the source data function, and initializing or assigning the processed data value to the target structure tree; when the original level information contains an array type data structure, the structure tree converter records the array level and traverses the index value.

5. The data conversion method of the API according to any one of claims 1 to 4, It is characterized in that The following steps are also included: S4: converting the source data into third target data according to the mapping configuration, and verifying whether the field type of the third target data is consistent with / inconsistent with the field type of the first target data; the verification items include at least one of direct mapping, field function processing, and array mapping layer correspondence; S5: If the field type of the third target data is consistent with the field type of the first target data, the verification result is verification passed; S6: Save into the warehouse, save the source data, the first target data, the third target data and the mapping configuration into the warehouse; S7: The verification result and the mapping configuration are transmitted to the user end, and the user end responds and saves the mapping configuration and the verification result.

6. An API data conversion system, used to implement the API data conversion method according to any one of claims 1 to 5, It is characterized in that include: Parsing module, mapping module, conversion module, generation module and calling module; The parsing module is used to parse the source data and the target data, and define the source structure tree and the target structure tree; The mapping module is used to establish the first mapping relationship, the second mapping relationship and the third mapping relationship, and generate a mapping configuration; The conversion module is used to realize the bidirectional conversion between source data and source structure tree, the bidirectional conversion between target data and target structure tree, and the conversion between source structure tree and target structure tree; The generating module is used to generate a conversion interface according to the mapping configuration, and cooperate with the calling module to verify the mapping configuration; The calling module is used to call the conversion interface or the proxy interface.

7. A method for configuring an API proxy interface, for configuring the conversion method according to any one of claims 1 to 5 in In the system as claimed in claim 6, It is characterized in that The following steps are involved: P1: Configure the first proxy interface on the user side and configure the third-party interface that needs to be called; P2: Select source data, parse the first mapping configuration of the first proxy interface, the first mapping configuration including: request body mapping configuration or response body mapping configuration; input simulation data, send the simulation data to the server, and call the first mapping configuration of the server; P3: The server converts the simulation data into request data according to the called first mapping configuration; the server sends a simulation request to the third-party service; the third-party service responds to the third-party interface and returns response data to the server; the server converts the response data into a response structure tree according to the first mapping configuration, and transmits the response structure tree to the user end; P4: The user end receives the response structure tree and confirms whether or not to generate the second proxy interface; if the second proxy interface needs to be generated, the user end saves the response structure tree and the second mapping configuration, wherein the second mapping configuration includes the response structure tree; P5: The server saves data into the database; P6: The server generates a second proxy interface, and transmits data of the second proxy interface back to the user end for the user end to call.

Citation Information

Patent Citations

  • A method and system for interacting with protocol messages and data based on descriptors

    CN111385292B

  • Method and device for generating page interface connector through model

    CN117850766A