Database query method, device and equipment based on WebAPI interface and storage medium

By using a database query method based on the WebAPI interface, the input parameter object and task number are converted into dictionary data, the execution script is obtained, and the database query is executed. This solves the high cost problem caused by independent design in existing technologies and achieves rapid response and low-cost interface development.

CN121858650APending Publication Date: 2026-04-14CHINA MOBILE GRP GUANGDONG CO LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202512029933.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-30
Publication Date
2026-04-14

AI Technical Summary

Technical Problem

Existing WebAPI interface design and development solutions are designed independently and are costly. When requirements change, they need to be recompiled and deployed, making it difficult to quickly respond to personalized interface requirements.

Method used

By using a single WebAPI interface to accommodate multiple interface requirements with different queries, input parameters, and outputs, the system converts input parameter objects and task numbers into dictionary data in a standard format, retrieves the execution script, performs database queries, and finally converts the result array into an output format to send to the client.

Benefits of technology

It enables rapid response to personalized interface requirements, reduces design and development costs, eliminates the need to recompile and deploy code for every change in requirements, and improves interface security and delivery efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121858650A_ABST
    Figure CN121858650A_ABST
Patent Text Reader

Abstract

The invention discloses a database query method, device and equipment based on a WebAPI interface and a storage medium, in the query method, WebAPI interface input parameters comprise an input parameter object and a task number, after a client sends a request message comprising the WebAPI interface input parameters, the WebAPI interface converts the input parameter object into dictionary data in a standard format, and the dictionary data in the standard format are stored in the database. The method comprises the following steps: acquiring a task number from a data center, acquiring a corresponding execution script from the data center according to the task number, assigning dictionary data to the acquired execution script, executing query of a database according to the execution script to obtain a result array, and finally converting the obtained result array into an output format and sending the output format to a client. The input parameters of the WebAPI interface are compatible with a plurality of interface requirements of different queries, different input parameters and different outputs by setting the input parameter objects and the task numbers, so that the design and development cost is effectively reduced while the personalized interface requirements are quickly responded, and code recompiling and redeployment online are not needed every time the requirements are changed.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of database query technology, and more particularly to a database query method, apparatus, device, and storage medium based on a WebAPI interface. Background Technology

[0002] Web API is an application programming interface (API) used for different software and applications to communicate and exchange data over a network. Unlike traditional APIs, Web API is based on the HTTP protocol, which enables it to work across platforms and languages, greatly improving the flexibility and scalability of applications.

[0003] In development scenarios such as mobile applications, IoT applications, and microservice architectures, WebAPIs are used in various scenarios that require interaction between systems or communication between devices. Therefore, in the process of developing and using WebAPIs, it is necessary to clarify what functions and interfaces the application needs, including determining the requirements for data input and output formats, API access permissions, and security.

[0004] The existing WebAPI design and development schemes involve designing, developing, and maintaining backend API interfaces independently based on specific needs to address various personalized requests for database information. However, each WebAPI interface in such a design and development scheme is independently designed, resulting in high development and maintenance costs. Furthermore, when requirements change, the WebAPI interface code logic needs to be modified and recompiled and deployed. Summary of the Invention

[0005] The purpose of this invention is to provide a database query method, apparatus, device, and storage medium based on a WebAPI interface. This method can accommodate multiple different query, input parameter, and output interface requirements through a single WebAPI interface. It can quickly respond to personalized interface requirements while effectively reducing design and development costs, eliminating the need to recompile code and redeploy for each change in requirements.

[0006] To achieve the above objectives, this invention discloses a database query method based on a WebAPI interface, comprising: A database query method based on a WebAPI interface is characterized by including: Receive a request message sent by the client that includes WebAPI interface input parameters, wherein the WebAPI interface input parameters include input parameter object and task number; Convert the input parameter object into dictionary data in standard format; Retrieve the corresponding execution script from the data center based on the task number; Assign the dictionary data to the obtained execution script; The database query is executed based on the assigned execution script to obtain a result array; The obtained result array is converted into an output format and sent to the client.

[0007] Furthermore, the request information also includes authentication information, and before the step of "converting the input parameter object into standard format dictionary data" it also includes: The validity of the request message is determined by verifying the authentication information. If the message is deemed valid, authorization for resources and operations is granted.

[0008] Furthermore, the step of "converting the input parameter object into dictionary data in a standard format" includes: Serialize the input parameter object into a JSON string format; The JSON string data is deserialized into dictionary data.

[0009] Furthermore, the dictionary data includes multiple pairs of combined keys and values, the execution script contains multiple parameter placeholders, and the step of "assigning the dictionary data to the acquired execution script" includes: Each of the keys is associated with the name of a plurality of the parameter placeholders; Replace the placeholders of the parameters corresponding to the keys with the values ​​corresponding to the keys.

[0010] Furthermore, the step of "converting the obtained result array into an output format and sending it to the client" includes: Serialize the result array into JSON format result information; Create a result carrier that includes content and content type, use the JSON formatted result information as the content, and set the content type to application / json; The structure carrier is sent to the client as a request response.

[0011] To achieve the above objectives, the present invention discloses a database query device based on a WebAPI interface, comprising: The receiving module is used to receive a request message sent by the client that includes WebAPI interface input parameters, wherein the WebAPI interface input parameters include input parameter objects and task numbers; A conversion module is used to convert the input parameter object into dictionary data in a standard format; The acquisition module is used to retrieve the corresponding execution script from the data center based on the task number; The assignment module is used to assign the dictionary data to the acquired execution script; The query module is used to execute database queries based on the assigned execution script to obtain a result array; The sending module is used to convert the obtained result array into an output format and send it to the client.

[0012] To achieve the above objectives, the present invention discloses an electronic device comprising: One or more processors; One or more memories are used to store one or more programs that, when executed by the processor, enable the processor to implement the database query method based on the WebAPI interface as described above.

[0013] To achieve the above objectives, the present invention discloses a computer-readable storage medium having a program stored thereon, which, when executed by a processor, implements the aforementioned database query method based on a WebAPI interface.

[0014] Compared with existing technologies, the WebAPI interface input parameters of this invention include input parameter objects and task numbers. After the client sends a request message containing WebAPI interface input parameters, the WebAPI interface converts the input parameter objects into dictionary data in a standard format, retrieves the corresponding execution script from the data center according to the task number, assigns the dictionary data to the retrieved execution script, and executes a database query based on this execution script to obtain a result array. Finally, the obtained result array is converted into an output format and sent to the client. The WebAPI interface input parameters, by setting input parameter objects and task numbers, are compatible with multiple interface requirements with different queries, different input parameters, and different outputs. This enables rapid response to personalized interface requirements while effectively reducing design and development costs, eliminating the need to recompile code and redeploy for each change in requirements. Attached Figure Description

[0015] Figure 1 This is a flowchart of a database query method based on a WebAPI interface according to an embodiment of the present invention.

[0016] Figure 2 This is a schematic diagram of the message structure in the database query method based on the WebAPI interface according to an embodiment of the present invention.

[0017] Figure 3 This is a schematic diagram of the structure of the SQL script body in the database query method based on the WebAPI interface according to an embodiment of the present invention.

[0018] Figure 4 This is a module diagram of a database query device based on a WebAPI interface according to an embodiment of the present invention.

[0019] Figure 5 This is a system diagram of an electronic device according to an embodiment of the present invention. Detailed Implementation

[0020] To illustrate the technical content, structural features, objectives, and effects of the present invention in detail, the following description is provided in conjunction with the embodiments and accompanying drawings.

[0021] Example 1 Please see Figures 1 to 3 This invention discloses a database query method based on a WebAPI interface, which includes: 101. Receive a request message sent by the client that includes WebAPI interface input parameters. The WebAPI interface input parameters include the input parameter object and the task number. Understandably, when a client sends a general Web API response request (HTTP request) via the POST request method, the message structure for querying data via the POST request is as follows: Figure 2 As shown, it includes URL parameters for annotating the FromQuery attribute, authentication information carrying the Authorization attribute, and input parameter message body for annotating the FromBody attribute.

[0022] Furthermore, the request information also includes authentication information, and before "converting the input parameter object into standard format dictionary data," it also includes: 1011. Verify the validity of the request message through authentication information. If the message is deemed valid, authorize the resources and operations accordingly.

[0023] Understandably, the authentication information (request headers) in the request message records an Authorization with a ContentType of application / json, which is used by the machine to perform authentication and authorization, to verify the legitimacy of the sent request, and to determine whether to allow the user to access resources or perform specific operations.

[0024] 102. Convert the input parameter object into dictionary data in standard format; Understandably, the input parameter body of the request message declares the name of the input parameter entity and data in JSON or XML format. The name is consistent with the SQL name of the task number in the URL parameter, and the data is a dynamic type and a JSON-formatted body (the input parameter object in this embodiment). This allows the dynamic parameters of the backend SQL to be obtained by reading the body of the HTTP request message, so that a WebAPI interface designed with RESTful can uniformly adapt to different parameter names and different numbers of parameters according to different actual needs.

[0025] Furthermore, "converting the input parameter object into dictionary data in a standard format" includes: 1021. Serialize the input parameter object into a JSON string format; 1022. Deserialize JSON string data into dictionary data.

[0026] Understandably, when the Request.ContentType of the received dynamic parameter is application / json, the received input parameter message content (the value of inArgs) needs to be serialized into a JSON string, and then the processed JSON string needs to be deserialized into dictionary data. The dictionary data includes keys (strings) and values ​​(objects), thereby processing the message data into dictionary data for subsequent database query parameters.

[0027] 103. Retrieve the corresponding execution script from the data center based on the task number; It is understandable that the URL parameters are designed as a unified Web API interface address for external services, and the SQL script content or view number to be executed in the backend configuration is determined by the taskno (task number in this embodiment), which is of type int and is JSON data in the URL parameters.

[0028] 104. Assign the dictionary data to the obtained execution script; Furthermore, the dictionary data includes multiple pairs of keys and values, and the execution script contains multiple parameter placeholders. "Assigning the dictionary data to the obtained execution script" includes: 1041. Assign multiple keys to the names of multiple parameter placeholders; 1042. Replace the placeholders of the parameters corresponding to the multiple keys with the multiple values ​​corresponding to the multiple keys respectively.

[0029] Understandably, the specific query or statistical script number to be executed in the current interface response is determined by querying the Query parameter task number (a unique identifier of the client request). Based on the determined script number, the corresponding SQL query execution script body is retrieved from the database or cache (the data center in this embodiment) through the interface layer. For example, the SQL script body for taskno=2 is as follows: Figure 3 As shown.

[0030] Understandably, performing parameterized assignment in an SQL script requires mapping the keys in the dictionary data to the parameter placeholders in the SQL query, and then replacing these placeholders with the corresponding values ​​in the dictionary data to assign values ​​to the retrieved object as SQL input parameters. For example, assuming the dictionary contains {"@paramValue", "7 days"}, then, as... Figure 3 As shown, the placeholder parameter named @paramValue in the SQL execution script will be assigned the value from the dictionary data.

[0031] 105. Execute the database query based on the assigned execution script to obtain the result array; 106. Convert the obtained result array into the output format and send it to the client.

[0032] Furthermore, "converting the obtained result array into an output format and sending it to the client" includes: 1061. Serialize the result array into JSON format result information; 1062. Create a result carrier that includes content and content type, using JSON formatted result information as content, and setting the content type to application / json; 1063. Send the structural carrier as a request response to the client.

[0033] Understandably, in this embodiment, by executing a parameterized database query based on the assigned SQL script, the dynamic array (list) requested by the client can be obtained. To return the result to the client, an OkObjectResult response body object (the result carrier in this embodiment) needs to be created first. Since the output interface of the WebAPI interface requires data in JSON or XML format, the query result data needs to be serialized into a JSON string or JSON object. Then, the serialized JSON string or JSON object is used as the content of the OkObjectResult response body object, and the corresponding Content-Type (header) of the OkObjectResult response body object is set to application / json. Finally, this OkObjectResult response body object is returned to the client as an HTTP response.

[0034] In the ICT field, the aforementioned API interfaces can be seamlessly integrated into existing business systems and workflows, significantly reducing the development and maintenance costs of information query and reporting interfaces. In particular, when dealing with changes in interface requirements after deployment, the aforementioned interface model can effectively improve interface security and quickly respond to actual changes in requirements without the need to recompile the interface or deploy the code, which is conducive to greatly improving delivery efficiency.

[0035] Compared with existing technologies, the WebAPI interface input parameters of this invention include input parameter objects and task numbers. After the client sends a request message containing WebAPI interface input parameters, the WebAPI interface converts the input parameter objects into dictionary data in a standard format, retrieves the corresponding execution script from the data center according to the task number, assigns the dictionary data to the retrieved execution script, and executes a database query based on this execution script to obtain a result array. Finally, the obtained result array is converted into an output format and sent to the client. The WebAPI interface input parameters, by setting input parameter objects and task numbers, are compatible with multiple interface requirements with different queries, different input parameters, and different outputs. This enables rapid response to personalized interface requirements while effectively reducing design and development costs, eliminating the need to recompile code and redeploy for each change in requirements.

[0036] Example 2 Please see Figures 1 to 4 This invention discloses a database query device based on a WebAPI interface, comprising: The receiving module 201 is used to receive a request message sent by the client that includes WebAPI interface input parameters. The WebAPI interface input parameters include the input parameter object and the task number. The conversion module 202 is used to convert the input parameter object into dictionary data in a standard format; Module 203 is used to retrieve the corresponding execution script from the data center based on the task number; Assignment module 204 is used to assign dictionary data to the obtained execution script; The query module 205 is used to execute a database query based on the assigned execution script in order to obtain a result array; The sending module 206 is used to convert the obtained result array into an output format and send it to the client.

[0037] Example 3 Please see Figures 1 to 5 This invention discloses an electronic device comprising: One or more processors 301; One or more memories 302 are used to store one or more programs that, when executed by a processor, enable the processor to implement the database query method based on the WebAPI interface as described above.

[0038] Example 4 This application discloses a computer-readable storage medium storing a program thereon, which, when executed by a processor, implements the aforementioned database query method based on a WebAPI interface.

[0039] Example 5 This application discloses a computer program product or computer program, which includes computer instructions stored in a computer-readable storage medium. A processor of an electronic device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the electronic device to perform the aforementioned database query method based on a WebAPI interface.

[0040] It should be understood that, in the embodiments of this application, the processor may be a central processing unit (CPU), but it may also be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor.

[0041] Those skilled in the art will understand that all or part of the processes in the above embodiments can be implemented by hardware related to computer program instructions. The program can be stored in a computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. The storage medium can be a magnetic disk, optical disk, read-only memory (ROM), or random access memory (RAM), etc.

[0042] The above-disclosed embodiments are merely preferred embodiments of the present invention and should not be construed as limiting the scope of the present invention. Therefore, any equivalent variations made in accordance with the claims of the present invention are still within the scope of the present invention.

Claims

1. A database query method based on a WebAPI interface, characterized in that, include: Receive a request message sent by the client that includes WebAPI interface input parameters, wherein the WebAPI interface input parameters include input parameter object and task number; Convert the input parameter object into dictionary data in standard format; Retrieve the corresponding execution script from the data center based on the task number; Assign the dictionary data to the obtained execution script; The database query is executed based on the assigned execution script to obtain a result array; The obtained result array is converted into an output format and sent to the client.

2. The database query method based on the WebAPI interface according to claim 1, characterized in that, The request information also includes authentication information, and before the step of "converting the input parameter object into standard format dictionary data" it also includes: The validity of the request message is determined by verifying the authentication information. If the message is deemed valid, authorization for resources and operations is granted.

3. The database query method based on the WebAPI interface according to claim 1, characterized in that, The phrase "converting the input parameter object into standard format dictionary data" includes: Serialize the input parameter object into a JSON string format; The JSON string data is deserialized into dictionary data.

4. The database query method based on the WebAPI interface according to claim 1, characterized in that, The dictionary data includes multiple pairs of keys and values, the execution script contains multiple parameter placeholders, and the step of "assigning the dictionary data to the acquired execution script" includes: Each of the keys is associated with the name of a plurality of the parameter placeholders; Replace the placeholders of the parameters corresponding to the keys with the values ​​corresponding to the keys.

5. The database query method based on the WebAPI interface according to claim 1, characterized in that, The phrase "converting the obtained result array into an output format and sending it to the client" includes: Serialize the result array into JSON format result information; Create a result carrier that includes content and content type, use the JSON formatted result information as the content, and set the content type to application / json; The structure carrier is sent to the client as a request response.

6. A database query device based on a WebAPI interface, characterized in that, include: The receiving module is used to receive a request message sent by the client that includes WebAPI interface input parameters, wherein the WebAPI interface input parameters include input parameter objects and task numbers; A conversion module is used to convert the input parameter object into dictionary data in a standard format; The acquisition module is used to retrieve the corresponding execution script from the data center based on the task number; The assignment module is used to assign the dictionary data to the acquired execution script; The query module is used to execute database queries based on the assigned execution script to obtain a result array; The sending module is used to convert the obtained result array into an output format and send it to the client.

7. An electronic device, characterized in that, include: One or more processors; One or more memories for storing one or more programs, which, when executed by the processor, cause the processor to implement the database query method based on a WebAPI interface as described in any one of claims 1 to 5.

8. A computer-readable storage medium having a program stored thereon, characterized in that, When the program is executed by the processor, it implements the database query method based on the WebAPI interface as described in any one of claims 1 to 5.