CN111159214B - API access method and device, electronic equipment and storage medium - Google Patents

API access method and device, electronic equipment and storage medium Download PDF

Info

Publication number
CN111159214B
CN111159214B CN201811319140.XA CN201811319140A CN111159214B CN 111159214 B CN111159214 B CN 111159214B CN 201811319140 A CN201811319140 A CN 201811319140A CN 111159214 B CN111159214 B CN 111159214B
Authority
CN
China
Prior art keywords
query
parameter
api
data tables
configuration information
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201811319140.XA
Other languages
Chinese (zh)
Other versions
CN111159214A (en
Inventor
陈学平
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
China Mobile Communications Group Co Ltd
China Mobile Suzhou Software Technology Co Ltd
Original Assignee
China Mobile Communications Group Co Ltd
China Mobile Suzhou Software Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by China Mobile Communications Group Co Ltd, China Mobile Suzhou Software Technology Co Ltd filed Critical China Mobile Communications Group Co Ltd
Priority to CN201811319140.XA priority Critical patent/CN111159214B/en
Publication of CN111159214A publication Critical patent/CN111159214A/en
Application granted granted Critical
Publication of CN111159214B publication Critical patent/CN111159214B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Landscapes

  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention mainly relates to the technical field of computer data processing, in particular to an API access method, an API access device, an API access electronic device and a API storage medium, which are used for solving the problem that complex query processing under multi-table connection cannot be supported. The method comprises the following steps: receiving a query request containing query parameters and a monitoring address of an accessed API; acquiring configuration information of the accessed API according to the monitoring address; determining at least two data tables corresponding to the API and association conditions among the data tables according to the configuration information; invoking the at least two data tables, and associating the at least two data tables according to the association condition; and searching for a query result corresponding to the query parameter according to the associated data table and outputting the query result.

Description

API access method and device, electronic equipment and storage medium
Technical Field
The present invention relates to the field of computer data processing technologies, and in particular, to an API (Application Programming Interface) access method, an API access device, an API access electronic device, and a storage medium.
Background
In the field of computer data processing technology, APIs are predefined functions that are designed to provide applications and developers the ability to access a set of routines based on certain software or hardware without having to access source code or understand the details of the internal operating mechanisms.
In the prior art, a table query method of a general API is designed, which aims to reduce the influence of the change of a table structure on the table query, improve the efficiency of development, integration and test and meet the flexible requirements of different services on the table query. The method comprises the following steps:
1. and setting a general API input format, supporting fuzzy query according to keywords, providing statistics and paging functions, and supporting sorting according to a certain field.
The API input format comprises: (1) providing a general parameter input: maximum record number of each page of limit, offset start mark, sort_dir sort mode, sort_key default corresponding sort field name, only_static statistics number identification, not putting detailed record, key_names table field name segment list, supporting multiple fields, key_value search key, sort_dir value range [ asc, desc ]; (2) Support the fuzzy query of "or" SQL statement of multiple fields in the table; (3) specifying the corresponding table to be queried in the URL of the query API.
When the parameter value of the API parameter only_static is true, only counting the number without inquiring a specific record item; when the API parameter only_static parameter value is False, a specific record item is queried.
2. Setting unified control logic to realize statistics of only the record quantity or feedback record quantity and a detailed record list; the unified control logic automatically distributes the interface information to a specific table statistics function and a table record inquiry function, combines the results of the functions, and feeds back the record number or record number and a detailed paging table record item list.
3. Packaging the universal statistics and query record functions.
According to the above description, the prior art provides a set of more general API query methods for opening the data in the table for the underlying data table. The scheme provides rich functions of fuzzy query, statistics, paging, sorting and the like, but according to the principle and sample codes, all operations and functions are based on a single table, and complex query processing under multi-table connection cannot be supported. In actual service requirements, the situation of multi-table connection is quite common, so that flexibility is poor, and most application scenes cannot be covered.
Disclosure of Invention
The embodiment of the invention provides an API access method, an API access device, an API access electronic device and a API storage medium, which are used for solving the problem that complex query processing under multi-table connection cannot be supported in the prior art.
The embodiment of the invention provides an access method of an application programming interface API, which comprises the following steps:
receiving a query request containing query parameters and a monitoring address of an accessed API;
acquiring configuration information of the accessed API according to the monitoring address;
determining at least two data tables corresponding to the API and association conditions among the data tables according to the configuration information;
Invoking the at least two data tables, and associating the at least two data tables according to the association condition;
and searching for a query result corresponding to the query parameter according to the associated data table and outputting the query result.
Further, according to the associated data table, searching the query result corresponding to the query field and outputting the query result includes:
judging whether the query parameter is an open field of a first type;
if so, determining a query field corresponding to the query parameter according to the corresponding relation between the saved field and the request parameter, searching a query result corresponding to the query field and outputting the query result;
if not, taking the query parameters as query fields, searching for query results corresponding to the query fields and outputting the query results.
Further, according to the associated data table, searching the query result corresponding to the query field and outputting the query result includes:
judging whether the query parameter is an open field of a second type;
if so, searching a query result corresponding to the query parameter, determining a return parameter corresponding to the query parameter according to the corresponding relation between the saved field and the return parameter, and outputting the query result containing the return parameter;
If not, taking the query parameters as query fields, searching for query results corresponding to the query fields, outputting the query results containing the query parameters.
Further, according to the associated data table, searching the query result corresponding to the query field and outputting the query result includes:
and filtering the query result according to preset filtering conditions, and outputting the query result obtained after filtering.
Further, the filtering conditions include at least one of:
=,!=,>,<,>=,<=。
further, after acquiring the configuration information of the accessed API, before determining at least two data tables corresponding to the API and association conditions between the data tables, the method further includes:
and processing the configuration information into a standard Structured Query Language (SQL) aiming at the configuration information.
Further, the associating the at least two data tables according to the association condition includes:
and according to the identification information of the associated columns in the association relation, associating the corresponding columns in the at least two data tables.
The embodiment of the invention also provides an API accessing device, which comprises:
the receiving module is used for receiving a query request containing query parameters and a monitoring address of the accessed API;
The acquisition module is used for acquiring the configuration information of the accessed API according to the monitoring address;
the determining module is used for determining at least two data tables corresponding to the API and association conditions among the data tables according to the configuration information;
the association module is used for calling the at least two data tables and associating the at least two data tables according to the association condition;
and the output module is used for searching the query result corresponding to the query parameter according to the associated data table and outputting the query result.
Further, the output module is specifically configured to determine whether the query parameter is an open field of the first type; if so, determining a query field corresponding to the query parameter according to the corresponding relation between the saved field and the request parameter, searching a query result corresponding to the query field and outputting the query result; if not, taking the query parameters as query fields, searching for query results corresponding to the query fields and outputting the query results.
Further, the output module is specifically configured to determine whether the query parameter is an open field of the second type; if so, searching a query result corresponding to the query parameter, determining a return parameter corresponding to the query parameter according to the corresponding relation between the saved field and the return parameter, and outputting the query result containing the return parameter; if not, taking the query parameters as query fields, searching for query results corresponding to the query fields and outputting the query results.
Further, the output module is specifically configured to filter the query result according to a preset filtering condition, and output a query result obtained after the filtering.
Further, the apparatus further comprises a processing module: the method is particularly used for processing the configuration information into a standard structured query language SQL aiming at the configuration information.
Further, the association module is specifically configured to associate corresponding columns in the at least two data tables according to identification information of the columns associated in the association relationship.
The invention provides an electronic device, comprising: a memory, a processor, and a receiver;
the processor is configured to read the program in the memory, and execute the steps of any one of the methods described above.
The present invention provides a computer readable storage medium storing a computer program executable by an electronic device, which when run on the electronic device causes the electronic device to perform the steps of any one of the methods described above.
The embodiment of the invention provides an API access method, an API access device, electronic equipment and a storage medium, wherein the method comprises the following steps: receiving a query request containing query parameters and a monitoring address of an accessed API; acquiring configuration information of the accessed API according to the monitoring address; determining at least two data tables corresponding to the API and association conditions among the data tables according to the configuration information; invoking the at least two data tables, and associating the at least two data tables according to the association condition; and searching for a query result corresponding to the query parameter according to the associated data table and outputting the query result. Because the configuration information stores at least two data tables for association and the association relation between the data tables, the corresponding data tables can be associated according to the configuration information, so that the query result is output according to the data tables obtained after association, and the requirement of complex query is met.
Drawings
FIG. 1 is a schematic diagram of an API design flow provided in embodiment 1 of the present invention;
FIG. 2 is a schematic diagram of an API access process according to embodiment 2 of the present invention;
FIG. 3 is a schematic diagram of an API query process provided in embodiment 6 of the present invention;
FIG. 4 is a schematic diagram of a process for processing association conditions according to embodiment 6 of the present invention;
FIG. 5 is a schematic diagram of a filtration conditioning process according to example 6 of the present invention;
fig. 6 is a schematic diagram of an API access procedure provided in embodiment 8 of the present invention;
fig. 7 is a schematic diagram of an API accessing device according to embodiment 9 of the present invention;
fig. 8 is a schematic structural diagram of an electronic device according to embodiment 10 of the present invention.
Detailed Description
For the purpose of making the technical solution and advantages of the present invention clearer, the present invention will be further described in detail with reference to the accompanying drawings. It will be apparent that the described embodiments are only some, but not all, of the embodiments of the invention. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
Example 1:
fig. 1 is a schematic diagram of an API design flow provided in an embodiment of the present invention, which mainly includes:
Connecting to a database according to the data source information, extracting metadata of a data table structure at the bottom layer of the database, and acquiring information lists of all data tables with authority, namely information lists of the data tables which can be accessed; the user can select one or more data tables, and further obtain information such as field names, field types and the like of each data table.
In order to ensure the security of the underlying structure information of the data table, certain fields in the data table may not be directly displayed on the user side, and for those fields which are not to be directly displayed on the user side, corresponding request parameters may be preset for the fields, or corresponding return parameters of the fields may be preset. If the corresponding relation between the fields and the request parameters is pre-stored, the request parameters are used as query parameters in the access of the user, the request parameters are automatically converted into fields in a data table for matching according to the corresponding relation between the pre-stored fields and the request parameters, the query fields corresponding to the query parameters are determined, and the query results corresponding to the query fields are searched and output; otherwise, directly taking the query parameters as query fields, searching the query results corresponding to the query fields and outputting the query results. If the pre-saved field corresponds to the return parameter, determining the return parameter corresponding to the query parameter contained in the received query request when the query result is returned, and returning the query result containing the return parameter to the user; otherwise, the query parameters are used as query fields, and query results corresponding to the query fields are searched for and returned to the query fields. The request parameters and the return parameters can shield the field information of the bottom data table, and the overall security of the system is improved.
For the fields which are not wanted to be directly displayed at the user side, the corresponding relation between the fields and the request parameters and the corresponding relation between the fields and the return parameters can be set at the same time, the request parameters are used as query parameters when the user accesses the fields, the request parameters are automatically converted into fields in a data table according to the corresponding relation between the pre-stored fields and the request parameters to be matched, the query fields corresponding to the query parameters are determined, the query results corresponding to the query fields are searched, then the return parameters corresponding to the query parameters are determined according to the corresponding relation between the stored fields and the return parameters, and finally the query results containing the return parameters are output.
According to the configuration information of the API, at least two data tables corresponding to the API and association conditions among the data tables can be determined, wherein the association conditions are used for association inquiry among a plurality of data tables, and the association conditions can be a plurality of data tables.
In many scenarios, the returned data needs to be filtered, so that the filtering conditions can be preset. The filtering conditions can be multiple, and the query results are filtered to obtain the query results meeting the search requirements of the user.
A globally unique snoop address is pre-configured for the API, which is used to uniquely identify a self-developed API. When the API access is carried out, the monitoring address is used for mapping the self-developed API, and then the data access is carried out. The information is stored to form configuration information of the API.
Example 2:
fig. 2 is a schematic diagram of an API access process according to an embodiment of the present invention, where the process includes the following steps:
s201: a query request including a query parameter and a listening address of an API being accessed is received.
The access method of the application programming interface API provided by the embodiment of the invention is applied to electronic equipment, wherein the electronic equipment can be mobile phones, personal Computers (PC), tablet computers and other equipment, and can also be servers, server clusters and other equipment.
In the embodiment of the invention, the monitoring address of the accessed API is preset, the monitoring address of the API uniquely identifies the API, and the user can access the API according to the monitoring address. For example: the snoop address is similar to http:// { ip: port }/{ project-name }/selfDefine/apis/myapi.
When a user inputs a query request, the electronic device receives a query parameter in the query request, the query parameter corresponds to a query field in the data table, and the electronic device can output a query result corresponding to the query parameter according to the query parameter. For example, the received query request may include a query parameter that is a "name" or the like.
The electronic device may receive a query request including a query parameter and a listening address of an API being accessed, where the receiving process is in the prior art, and the embodiments of the present invention are not described herein.
S202: and acquiring configuration information of the accessed API according to the monitoring address.
In the embodiment of the invention, the monitoring address of the accessed API is preset, the monitoring address of the API is used for uniquely identifying the API, after the electronic equipment receives the query request, the electronic equipment accesses the corresponding API according to the monitoring address of the API contained in the query request, and acquires the configuration information of the API, wherein the configuration information of the API is preset, the configuration information of the API contains the identification information of the data table corresponding to the API, and the identification information can be the table name of the data table.
S203: and determining at least two data tables corresponding to the API and association conditions among the data tables according to the configuration information.
Specifically, in order to better meet the search requirement of the user, when the API design is performed, the data table with the association relationship is associated and stored in the configuration information, and the specific configuration information can be stored: table name of the data table, associated column name, associated condition, wherein the associated column name may be an associated field.
Therefore, after the configuration information of the API is obtained, table names of the at least two data tables, associated column names of the at least two data tables, and association conditions between the at least two data tables can be obtained according to the configuration information, and the at least two data tables can be associated according to the associated column names of the at least two data tables and the association conditions.
When the API is designed, the number of the associated data tables can be two or more, so that the electronic equipment determines that the number of the data tables corresponding to the API can be two or more, and preferably, the number of the data tables corresponding to the API can be more than one according to the configuration information of the API. For example: the data table may be A, B, C, D, E, or the like, depending on the configuration information of the API.
Based on the configuration information of the API, association conditions between the data tables may also be determined. And after the association conditions are determined, the at least two data tables are associated according to the column names of the association of the at least two data tables and the association conditions.
S204: and calling the at least two data tables, and associating the at least two data tables according to the association condition.
The configuration information of the API stores table names of the data tables having the association relationship, so that at least two data tables having the association relationship can be called according to the configuration information, and the configuration information of the API stores associated columns and association conditions, so that at least two data tables having the association relationship can be called according to the table names of the data tables having the association relationship stored in the configuration information, and the at least two data tables are associated according to the associated column names of the at least two data tables and the association conditions of the at least two data tables stored in the configuration information. Specifically, the process of associating according to the association condition is the prior art, and the embodiments of the present invention are not described in detail.
S205: and searching for a query result corresponding to the query parameter according to the associated data table and outputting the query result.
After the at least two data tables are associated according to the association condition, a data table may be generated, the configuration information of the API stores the identification information of the columns of the at least two data tables associated, for example, 5 columns in data table 1 and 4 columns in data table 2, and if the columns C in data table 1 and D in data table 2 are both IDs, then data table 1 and data table 2 may be associated, and after data table 1 and data table 2 are associated, the generated data table 3 includes all columns of data table 1 and data table 2, and total 8 columns. According to the generated data table, searching the query result corresponding to the query parameter, and outputting the query result.
According to the method and the device for processing the query request, the query request comprising the query parameter and the accessed monitoring address of the API is received, so that the configuration information of the API can be obtained according to the monitoring address, at least two data tables corresponding to the API and the association condition between the data tables can be determined according to the configuration information of the API, the at least two data tables are associated according to the association condition between the data tables by calling the at least two data tables, the query result corresponding to the query parameter can be searched according to the information in the associated data tables, and the query result is output, so that the problem that complex query processing under multi-table connection cannot be supported is solved.
Example 3:
in order to improve the security of API access, in the foregoing embodiment of the present invention, according to the associated data table, searching the query result corresponding to the query field and outputting the query result includes:
judging whether the query parameter is an open field of a first type;
if so, determining a query field corresponding to the query parameter according to the corresponding relation between the saved field and the request parameter, searching a query result corresponding to the query field and outputting the query result;
if not, taking the query parameters as query fields, searching for query results corresponding to the query fields and outputting the query results.
In order to ensure the security of the data table structure of the bottom layer of the database, if the query field corresponding to the query parameter contained in the received query request is completely consistent with the field in the data table structure, the user can know the structure of the bottom layer data table through the input query request when accessing the API, and such processing is unsuitable in some information sensitive fields.
In order to determine whether some fields in the data table need to be set to be not displayed on the user side, if so, according to the corresponding relation between the pre-stored fields and the request parameters, the corresponding relation can be that after the fields are encrypted, the request parameters are obtained; if the query parameters contained in the query request are request parameters, determining the query fields corresponding to the query parameters taking the request parameters as the query parameters according to the corresponding relation between the saved fields and the request parameters, searching the query results corresponding to the query fields, and outputting the query results.
If the query parameters contained in the query request are not the request parameters, directly taking the query parameters as query fields, searching the query results corresponding to the query fields, and outputting the query results.
In order to protect the underlying table structure of the database, if the query parameter included in the received query request is a request parameter, that is, a development field of the first type, that is, a request parameter obtained by encrypting the field, because the correspondence between the field and the request parameter is stored in the electronic device, the correspondence between the field and the request parameter may be set by a programmer in the design process of the API. For example, an interface definition sample of the correspondence between a preset field and a request parameter:
parameter explanation:
tableselect list: list of selected table information
tableName: selected table name
tablecolumnSelectList: selected list of column information
columnName: selected column name
columnType: column type is identified numerically because in the Java language standard, processing a database column type returns the column type number and further processing it
aspopencolumn: whether or not to be an open column
requestParamName: custom request parameters
According to the method and the device for inquiring the database, according to the corresponding relation between the fields and the request parameters, the inquiring fields corresponding to the inquiring parameters can be determined according to the corresponding relation, so that the inquiring results corresponding to the inquiring fields are obtained and output, and the safety of the database bottom table structure is guaranteed.
Example 4:
in order to ensure the security of the API access more accurately, in the embodiments of the present invention, the searching the query result corresponding to the query field and outputting the query result according to the associated data table includes:
judging whether the query parameter is an open field of a second type;
if so, searching a query result corresponding to the query parameter, determining a return parameter corresponding to the query parameter according to the corresponding relation between the saved field and the return parameter, and outputting the query result containing the return parameter;
if not, taking the query parameters as query fields, searching for query results corresponding to the query fields and outputting the query results.
In order to provide a richer method for protecting the table structure of the database bottom layer, the preset open field is provided with a second type of open field in addition to the first type of open field in the above embodiment.
In order to determine whether some fields in the data table need to be set to be not displayed on the user side, if so, searching for a query result corresponding to the query parameter, and obtaining a return parameter after encrypting the fields according to a pre-stored corresponding relation between the fields and the return parameter; and displaying the returned parameters as the fields at the user side and outputting the query results of the query parameters.
If the query parameter contained in the query request is not the open field of the second type, the query parameter is used as a query field, and a query result corresponding to the query field is searched and output.
The correspondence between the fields and the return parameters may be set by a programmer during the design of the API. For example, an interface definition sample of the correspondence between a preset field and a return parameter:
parameter explanation:
tableselect list: list of selected table information
tableName: selected table name
tablecolumnSelectList: selected list of column information
columnName: selected column name
columnType: column type is identified numerically because in the Java language standard, processing a database column type returns the column type number and further processing it
aspopencolumn: whether or not to be an open column
responsepalaramname: custom return parameters
asRequestParam: whether or not to customize return parameters
Because the embodiment of the invention judges whether the query parameters contained in the received query request are open fields of the second type or not, if so, the return parameters corresponding to the query fields are searched, and a query result containing the return parameters is output; if not, the query parameters are used as query fields, query results corresponding to the query fields are searched, and the query results are output, so that the aim of ensuring the safety of the data bottom layer table structure is fulfilled.
Example 5:
in order to better meet the search requirement of the user, in the above embodiments of the present invention, the searching the query result corresponding to the query field and outputting the query result according to the associated data table includes:
and filtering the query result according to preset filtering conditions, and outputting the query result obtained after filtering.
In order to better meet the search requirement of the user, when the query result corresponding to the query parameter included in the received query request is searched by the method in the above embodiment, there are many possible searched query results, and only some of the query results are needed by the user, at this time, in order to reduce the workload of the user to search the needed query results, the filtering condition may be preset, and the interface design of the filtering condition may be set by a programmer, for example, a sample of the filtering condition interface is preset:
Parameter explanation:
filterCondition SelectList: list of filtering conditions
tableName: filtering table name
columnName: filter column name
columnType: column type
value: values of the filtering conditions
operation: comparison operation
logic: a logic operation, which may be one of AND ("AND"), OR ("OR")
According to preset filtering conditions, the query results can be filtered, and the filtered query results which more meet the requirements of users are output.
According to the embodiment of the invention, the query result is filtered according to the preset filtering condition, and the query result obtained after the filtering is output, so that the aim of meeting the search requirement of the user is fulfilled.
In order to filter the search result more accurately, on the basis of the above embodiments, in the embodiments of the present invention, the filtering conditions include at least one of the following:
=,!=,>,<,>=,<=。
by filtering the condition EQ ("="), NE ("|="), GT (">), LT (" < "), GTE (" > = "), LTE (" <= "), the query result satisfying the user requirement can be filtered out, for example, the user wants to query that the name is Zhang san in the obtained query result, at this time, the electronic device can filter through EQ (" = "), that is, the name=Zhang san, and can output the query result named Zhang san on the basis of the query result. NE ("|="), GT (">), LT (" < "), GTE (" > = "), LTE (" <= ") are similar in method of use to EQ (" = "), and will not be described again.
Due to the filtering conditions in the embodiment of the invention, the query result can be filtered through the filtering conditions, and the filtered query result is searched and output, so that the query result which meets the requirements of users more is obtained.
Example 6:
in order to enable the API to access, more kinds of databases can be adapted, on the basis of the foregoing embodiments, in the embodiments of the present invention, after obtaining the configuration information of the accessed API, before determining at least two data tables corresponding to the API and the association condition between the data tables, the method further includes:
and processing the configuration information into a standard Structured Query Language (SQL) aiming at the configuration information.
In the prior art, if like queries act on non-VARCHAR fields, there will be problems in some databases, such as INT type fields, mySQL may support like, but Oracle does not, which is not a generic SQL writing method in the prior art. The code in the prior art is for example:
If hasattr(table_model,key_name):
Sql_string=+key_name like%key_value%+“or”
in the embodiment of the invention, after the configuration information of the accessed API is acquired, the configuration information can be converted into a standard structured query language SQL in order to enable the API to adapt to a wider variety of databases. The process of converting the configuration information of the API into the standard structured query language SQL is the prior art, and in the embodiment of the present invention, the description of the process is omitted.
FIG. 3 is a schematic diagram of an API query process provided in an embodiment of the present invention, according to a monitor address, configuration information of an API is obtained, table names of associated data tables are stored in the configuration information, as shown in the figure, for example, table names of two data tables stored in the configuration information are respectively table A and table B, each column (column) is read, and according to each stored data table and a column included in the data table, a data table to which each column belongs is determined, so as to form a (from) data table A and a data table B, columns in the data table A are respectively a column A and a column B, and the column A can be called cA and the column B can be called cB; columns in data table B are C columns, which may be referred to as cC, and D columns, which may be referred to as cD, respectively. The field which is preset as the request parameter and corresponds to the E column in the data table A is output according to the corresponding relation between the stored request parameter and the field when the query request which takes the request parameter as the query parameter is received, and the query result which corresponds to the query parameter is namely $value in the graph.
Specifically, the API configuration information is converted into SQL, and the converted SQL statement is similar to the SQL statement:
SELECT tableA.columnAas cA,tableB.columnC as cC FROM tableA,tableB
WHERE tableA.columnE=1
the corresponding relation processing method of the field and the return parameter is similar to the field and the request parameter, and is not repeated.
Fig. 4 is a schematic diagram of a processing procedure of association conditions provided in the embodiment of the present invention, where configuration information of an API is obtained according to a listening address, information associated with a data table a and a data table B is stored in the configuration information, specifically, an F column in the data table a is stored and an G column in the data table B is associated with an association condition EQ ("=") is used, so after the configuration information is obtained, the configuration information is converted into an SQL statement, and the converted SQL statement is similar to the SQL statement:
SELECT tableA.columnA as cA,tableB.columnC as cC FROM tableA,tableB
WHERE tableA.columnE=1AND(tableA.columnF=tableB.columnG)
fig. 5 is a schematic diagram of a filtering condition processing procedure provided in an embodiment of the present invention, where configuration information of an API is obtained according to a listening address, and according to a query parameter and the configuration information, a query result corresponding to the query parameter is determined to be a data table a, specifically, column H in the data table a, and a filtering condition LIKE ("LIKE") is adopted to filter the query result obtained through the above operation, where the filtering content is 'data'.
For the configuration information, SQL sentences are converted, and the converted SQL sentences are similar to the following steps:
SELECT tableA.columnA as cA,tableB.columnC as cC FROM tableA,tableB
WHERE tableA.columnE=1AND(tableA.columnF=tableB.columnG)AND
(tableA.columnH LIKE'%data%'AND tableB.columnI like'%my%')
and judging whether the number needs to be spliced or not according to the field type returned by the bottom data table. This can translate to standard SQL and fit most data queries.
After the configuration information of the API is processed into the standardized structured query language SQL, the data in the data table may be obtained according to the obtained SQL. For example:
Request parameter data samples: the API is preset with a field corresponding to a request parameter myname as a packageName, and when a user accesses the API, the user uses the myname to request the request, and the value is an engine.
http://{ip:port}/{project-name}/selfdefine/apis/myapi---POST
{
"myname":"engine"
}
Returning a data sample: the API defines two return parameters, namely, a yourname mapping packageName and a yourtime mapping createTime, is matched to the preservation with the value of engine according to the query condition, and the return data is displayed by using yourname and yourtime.
The configuration information of the API is processed into the standard structured query language SQL, so that the API can be ensured to adapt to more kinds of databases when being accessed, and the searching requirement of a user can be better met.
Example 7:
in order to make the association process clearer, on the basis of the foregoing embodiments, in an embodiment of the present invention, the associating the at least two data tables according to the association condition includes:
and according to the identification information of the associated columns in the association relation, associating the corresponding columns in the at least two data tables.
In order to be able to associate at least two data tables, the configuration information of the API is preset with identification information of a column that can be associated, where the identification information uniquely identifies the column in the data tables, and the at least two data tables can be associated through the identification information. For example: the data table A and the data table B are preset with an association relation, wherein a column A exists in the data table A, a column A also exists in the data table B, and the data table A and the data table B are associated according to the association condition and the associated column name according to the identification information of the column A.
Because the identification information of the associated columns in the association relation provided by the embodiment of the invention can associate at least two data tables by the identification information of the associated columns, the associated data tables can be queried, and query results can be output, so that the search requirements of users are met.
Example 8:
based on the above embodiments, in the embodiments of the present invention, a user may access an API, and fig. 6 is a schematic diagram of an API access flow provided in the embodiments of the present invention, which mainly includes:
receiving a query request containing a query parameter and a listening address of the accessed API, accessing the self-developed API according to the listening address, the access address being similar to that of the self-developed API because the listening address is globally unique: http:// { ip: port }/{ project-name }/selfdefine/apis/myapi.
According to the monitoring address, the configuration information of the API can be obtained and converted into standard SQL.
According to the configuration information of the API, the correspondence between the fields and the request parameters and the correspondence between the fields and the return parameters may be pre-saved, where the query parameter included in the query request received in fig. 6 is a request parameter myname, and the field corresponding to the request parameter is a packageName; the method can also be used for setting a return parameter as a yourname in a field packageName in a data table; the return parameter preset for the field createTime is yourtime;
Outputting a query result containing a return parameter according to SQL query data, namely outputting a query result containing the return parameter as a query parameter myname, wherein the output query result containing the return parameter is 'you time': 1529390195897, "you name": "Engine".
Because the configuration information of the API stores at least two data tables for association and the association relation between the data tables, the access flow of the API provided by the embodiment of the invention can associate the corresponding data tables according to the configuration information, thereby outputting the query result according to the data tables obtained after association, and meeting the requirement of complex query.
Example 9:
fig. 7 provides an apparatus for accessing an API, which is applied to an electronic device, and the apparatus includes:
a receiving module 701, configured to receive a query request including a query parameter and a listening address of an API being accessed;
an obtaining module 702, configured to obtain configuration information of the accessed API according to the listening address;
a determining module 703, configured to determine at least two data tables corresponding to the API and association conditions between the data tables according to the configuration information;
The association module 704 is configured to invoke the at least two data tables, and associate the at least two data tables according to the association condition;
and the output module 705 is configured to search for and output a query result corresponding to the query parameter according to the associated data table.
Further, the output module 705 is specifically configured to determine whether the query parameter is an open field of the first type; if so, determining a query field corresponding to the query parameter according to the corresponding relation between the saved field and the request parameter, searching a query result corresponding to the query field and outputting the query result; if not, taking the query parameters as query fields, searching for query results corresponding to the query fields and outputting the query results.
Further, the output module 705 is specifically configured to determine whether the query parameter is an open field of the second type; if so, searching a query result corresponding to the query parameter, determining a return parameter corresponding to the query parameter according to the corresponding relation between the saved field and the return parameter, and outputting the query result containing the return parameter; if not, taking the query parameters as query fields, searching for query results corresponding to the query fields and outputting the query results.
Further, the output module 705 is specifically configured to filter the query result according to a preset filtering condition, and output the query result obtained after the filtering.
Further, the apparatus further comprises: and the processing module 706 is configured to process the configuration information into a standard structured query language SQL for the configuration information.
Further, the association module 704 is specifically configured to associate corresponding columns in the at least two data tables according to the identification information of the columns associated in the association relationship.
Example 10:
on the basis of the above embodiments, fig. 8 is a schematic structural diagram of an electronic device according to an embodiment of the present invention, including a memory 801, a processor 802, and a transceiver 803;
the processor 802 is configured to execute the program in the read memory 801, and perform the following procedures:
the control transceiver 803 receives a query request containing a query parameter and a listening address of the accessed API;
acquiring configuration information of the accessed API according to the monitoring address;
determining at least two data tables corresponding to the API and association conditions among the data tables according to the configuration information;
Invoking the at least two data tables, and associating the at least two data tables according to the association condition;
and searching for a query result corresponding to the query parameter according to the associated data table and outputting the query result.
Based on the same inventive concept, the embodiment of the present invention further provides an electronic device, and since the principle of solving the problem of the electronic device is similar to that of the API access method, implementation of the electronic device may refer to implementation of the method, and repeated descriptions are omitted.
In fig. 8, a bus architecture may be comprised of any number of interconnected buses and bridges, and in particular, one or more processors represented by the processor 802 and various circuits of memory represented by the memory 801. The bus architecture may also link together various other circuits such as peripheral devices, voltage regulators, power management circuits, etc., which are well known in the art and, therefore, will not be described further herein. The transceiver 803 may be a plurality of elements, i.e., comprising a transmitter and a receiver, providing a means for communicating with various other apparatus over a transmission medium. The processor 802 is responsible for managing the bus architecture and general processing, and the memory 801 may store data used by the processor 802 in performing operations.
Alternatively, the processor 802 may be a CPU (Central processing Unit), ASIC (Application Specific Integrated Circuit ), FPGA (Field-Programmable Gate Array, field programmable Gate array), or CPLD (Complex Programmable Logic Device ).
The processor 802 is specifically configured to determine whether the query parameter is an open field of a first type;
if so, determining a query field corresponding to the query parameter according to the corresponding relation between the saved field and the request parameter, searching a query result corresponding to the query field and outputting the query result;
if not, taking the query parameters as query fields, searching for query results corresponding to the query fields and outputting the query results.
The processor 802 is specifically configured to determine whether the query parameter is an open field of a second type;
if so, searching a query result corresponding to the query parameter, determining a return parameter corresponding to the query parameter according to the corresponding relation between the saved field and the return parameter, and outputting the query result containing the return parameter;
if not, taking the query parameters as query fields, searching for query results corresponding to the query fields and outputting the query results.
The processor 802 is specifically configured to filter the query result according to a preset filtering condition, and output the query result obtained after the filtering.
The filtering conditions include at least one of: =, +|! =, <, =, < =.
The processor 802 is further configured to process the configuration information into a standard structured query language SQL for the configuration information.
The processor 802 is specifically configured to associate corresponding columns in the at least two data tables according to the identification information of the associated columns in the association relationship.
In the embodiment of the invention, the electronic equipment can acquire the configuration information of the API according to the monitoring address by receiving the query request containing the query parameter and the monitoring address of the accessed API, and can determine at least two data tables corresponding to the API and the association condition between the data tables according to the configuration information; and calling at least two data tables, associating the at least two data tables according to association conditions, and searching and outputting a query result corresponding to the query parameter according to the associated data tables without manual additional configuration, so that the efficiency and the correctness are improved, and the maintainability is improved.
Example 11:
on the basis of the above embodiments, the embodiments of the present invention further provide a computer-readable storage medium having stored therein a computer program executable by an electronic device, which when run on the electronic device, causes the electronic device to perform the steps of:
receiving a query request containing query parameters and a monitoring address of an accessed API;
acquiring configuration information of the accessed API according to the monitoring address;
determining at least two data tables corresponding to the API and association conditions among the data tables according to the configuration information;
invoking the at least two data tables, and associating the at least two data tables according to the association condition;
and searching for a query result corresponding to the query parameter according to the associated data table and outputting the query result.
The computer readable storage medium may be any available medium or data storage device that can be accessed by a processor in an electronic device, including but not limited to magnetic memories such as floppy disks, hard disks, magnetic tapes, magneto-optical disks (MO), etc., optical memories such as CD, DVD, BD, HVD, etc., and semiconductor memories such as ROM, EPROM, EEPROM, nonvolatile memories (NAND FLASH), solid State Disks (SSD), etc.
The computer readable storage medium provided by the embodiment of the invention stores the computer program, when the computer program is executed by the processor, the method comprises the steps of receiving a query request containing query parameters and a monitoring address of an accessed API, acquiring configuration information of the API according to the monitoring address, and determining at least two data tables corresponding to the API and association conditions among the data tables according to the configuration information; and calling at least two data tables, associating the at least two data tables according to association conditions, and searching and outputting a query result corresponding to the query parameter according to the associated data tables without manual additional configuration, so that the efficiency and the correctness are improved, and the maintainability is improved.
The embodiment of the invention provides an API access method, an API access device, electronic equipment and a storage medium, wherein the method comprises the following steps: receiving a query request containing query parameters and a monitoring address of an accessed API; acquiring configuration information of the accessed API according to the monitoring address; determining at least two data tables corresponding to the API and association conditions among the data tables according to the configuration information; invoking the at least two data tables, and associating the at least two data tables according to the association condition; and searching for a query result corresponding to the query parameter according to the associated data table and outputting the query result. Because the configuration information stores at least two data tables for association and the association relation between the data tables, the corresponding data tables can be associated according to the configuration information, so that the query result is output according to the data tables obtained after association, and the requirement of complex query is met.
For system/device embodiments, the description is relatively simple as it is substantially similar to method embodiments, with reference to the description of method embodiments in part.
It should be noted that in this document relational terms such as first and second, and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions.
It will be appreciated by those skilled in the art that embodiments of the present application may be provided as a method, system, or computer program product. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely application embodiment, or an embodiment combining application and hardware aspects. Furthermore, the present application may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present application is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems) and computer program products according to embodiments of the application. It will be understood that each flow and/or block of the flowchart illustrations and/or block diagrams, and combinations of flows and/or blocks in the flowchart illustrations and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
While preferred embodiments of the present invention have been described, additional variations and modifications in those embodiments may occur to those skilled in the art once they learn of the basic inventive concepts. It is therefore intended that the following claims be interpreted as including the preferred embodiments and all such alterations and modifications as fall within the scope of the invention.
It will be apparent to those skilled in the art that various modifications and variations can be made to the present invention without departing from the spirit or scope of the invention. Thus, it is intended that the present invention also include such modifications and alterations insofar as they come within the scope of the appended claims or the equivalents thereof.

Claims (13)

1. A method for accessing an API, said method comprising:
receiving a query request containing query parameters and a monitoring address of an accessed API;
acquiring configuration information of the accessed API according to the monitoring address, wherein the configuration information stores table names, associated column names and associated conditions of a data table;
determining at least two data tables corresponding to the API and association conditions among the data tables according to the configuration information;
invoking the at least two data tables, and associating the at least two data tables according to the association condition and the associated column name;
searching for a query result corresponding to the query parameter according to the associated data table and outputting the query result;
wherein, according to the associated data table, searching the query result corresponding to the query parameter and outputting the query result comprises:
Judging whether the query parameter is an open field of a first type;
if so, determining a query field corresponding to the query parameter according to the corresponding relation between the saved field and the request parameter, searching a query result corresponding to the query field and outputting the query result;
if not, taking the query parameters as query fields, searching for query results corresponding to the query fields and outputting the query results.
2. The method of claim 1, wherein searching for the query result corresponding to the query parameter and outputting the query result according to the associated data table comprises:
judging whether the query parameter is an open field of a second type;
if so, searching a query result corresponding to the query parameter, determining a return parameter corresponding to the query parameter according to the corresponding relation between the saved field and the return parameter, and outputting the query result containing the return parameter;
if not, taking the query parameters as query fields, searching for query results corresponding to the query fields and outputting the query results.
3. The method of claim 1, wherein searching for the query result corresponding to the query parameter and outputting the query result according to the associated data table comprises:
And filtering the query result according to preset filtering conditions, and outputting the query result obtained after filtering.
4. A method according to claim 3, wherein the filtering conditions comprise at least one of:
=,!=,>,<,>=,<=。
5. the method of claim 1, wherein after obtaining configuration information of the accessed API, before determining at least two data tables corresponding to the API and association conditions between the data tables, the method further comprises:
and processing the configuration information into a standard Structured Query Language (SQL) aiming at the configuration information.
6. The method of claim 1, wherein said associating the at least two data tables according to the association condition comprises:
and according to the identification information of the associated columns in the association relation, associating the corresponding columns in the at least two data tables.
7. An apparatus for accessing an API, said apparatus comprising:
the receiving module is used for receiving a query request containing query parameters and a monitoring address of the accessed API;
the acquisition module is used for acquiring configuration information of the accessed API according to the monitoring address, wherein the configuration information stores table names, associated column names and associated conditions of the data table;
The determining module is used for determining at least two data tables corresponding to the API and association conditions among the data tables according to the configuration information;
the association module is used for calling the at least two data tables and associating the at least two data tables according to the association condition and the associated column name;
the output module is used for searching the query result corresponding to the query parameter according to the associated data table and outputting the query result;
the output module is specifically configured to determine whether the query parameter is an open field of a first type; if so, determining a query field corresponding to the query parameter according to the corresponding relation between the saved field and the request parameter, searching a query result corresponding to the query field and outputting the query result; if not, taking the query parameters as query fields, searching for query results corresponding to the query fields and outputting the query results.
8. The apparatus of claim 7, wherein the output module is specifically configured to determine whether the query parameter is an open field of a second type; if so, searching a query result corresponding to the query parameter, determining a return parameter corresponding to the query parameter according to the corresponding relation between the saved field and the return parameter, and outputting the query result containing the return parameter; if not, taking the query parameters as query fields, searching for query results corresponding to the query fields and outputting the query results.
9. The apparatus of claim 7, wherein the output module is specifically configured to filter the query result according to a preset filtering condition, and output a query result obtained after the filtering.
10. The apparatus of claim 7, wherein the apparatus further comprises:
and the processing module is used for processing the configuration information into a standard Structured Query Language (SQL) aiming at the configuration information.
11. The apparatus of claim 7, wherein the association module is specifically configured to associate corresponding columns in the at least two data tables according to identification information of the columns associated in the association relationship.
12. An electronic device comprising a memory, a processor, and a receiver;
the processor is configured to read the program in the memory, and execute the steps of the method according to any one of claims 1 to 6.
13. A computer readable storage medium, characterized in that it stores a computer program executable by an electronic device, which when run on the electronic device causes the electronic device to perform the steps of the method according to any one of claims 1-6.
CN201811319140.XA 2018-11-07 2018-11-07 API access method and device, electronic equipment and storage medium Active CN111159214B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201811319140.XA CN111159214B (en) 2018-11-07 2018-11-07 API access method and device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201811319140.XA CN111159214B (en) 2018-11-07 2018-11-07 API access method and device, electronic equipment and storage medium

Publications (2)

Publication Number Publication Date
CN111159214A CN111159214A (en) 2020-05-15
CN111159214B true CN111159214B (en) 2024-01-26

Family

ID=70555334

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201811319140.XA Active CN111159214B (en) 2018-11-07 2018-11-07 API access method and device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN111159214B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115348209B (en) * 2022-10-18 2023-03-24 江西锦路科技开发有限公司 Flow control method and device of API (application program interface), electronic equipment and storage medium

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101196926A (en) * 2007-12-29 2008-06-11 中国建设银行股份有限公司 Database access platform and access method thereof

Also Published As

Publication number Publication date
CN111159214A (en) 2020-05-15

Similar Documents

Publication Publication Date Title
US9230083B2 (en) Securing application information in system-wide search engines
WO2018177252A1 (en) Block chain-based data storage and query method and device
US20160179816A1 (en) Near Real Time Auto-Suggest Search Results
RU2387003C2 (en) Method, system and device for detecting data sources and connection to data sources
US8868595B2 (en) Enhanced control to users to populate a cache in a database system
US10339330B2 (en) Data aggregation system for enabling query operations on restricted data that originates from multiple independent multiple sources
CN111352902A (en) Log processing method and device, terminal equipment and storage medium
US10120916B2 (en) In-querying data cleansing with semantic standardization
CN109063077B (en) Data access method and device based on elastic search
US20220075774A1 (en) Executing conditions with negation operators in analytical databases
MX2013014800A (en) Recommending data enrichments.
US20190012323A1 (en) Apparatus and Method for Accessing Data from a Database as a File
CN111159215B (en) Mapping method and device for Java class and relational database and computing equipment
US20200097673A1 (en) Data privilage control method and system
WO2019127772A1 (en) Data dictionary display method and device, terminal device and storage medium
CN113568924A (en) Data processing method and device, electronic equipment and storage medium
CN111984712B (en) Information processing method, device and storage medium
CN111159214B (en) API access method and device, electronic equipment and storage medium
CN111339560B (en) Data isolation method, device and system
US20230153455A1 (en) Query-based database redaction
CN112052254B (en) Data encapsulation method, electronic device and storage medium
CN111475505B (en) Data acquisition method and device
CN115098588A (en) Cross-cluster metadata synchronization method, device and medium
CN115827589A (en) Authority verification method and device, electronic equipment and storage medium
US20220138186A1 (en) Data set acquisition method, terminal device and computer readable storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant