API interface development method and device, equipment and storage medium

Through the API interface development method, the interface implementation is determined using HTTP servers and interceptors, and the requests and results are processed through processors and implementation methods, the problem of insufficient interface flexibility and scalability is solved, real-time modification and hot update of the interface are realized, and complex enterprise-level application integration is supported.

CN119690423APending Publication Date: 2025-03-25HENAN HUJIAJIA HEALTH TECH CO LTD

Patent Information

Application Number
CN202411867366.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-18
Publication Date
2025-03-25

AI Technical Summary

Technical Problem

The existing technology has limitations in terms of interface flexibility and scalability, and it is difficult to meet the challenges brought by changes in business needs and technological advancements.

Method used

By providing an API interface development method, the target HTTP request is determined using an HTTP server and an interceptor, the target interface implementation is determined based on the interface definition table and the binding relationship table, and the interface flexibility and scalability are realized through the preprocessor, implementation method and postprocessor to process the requests and results.

Benefits of technology

Real-time modification and thermal update of interfaces are realized, the scalability and flexibility of interfaces are improved, and complex enterprise-level application integration scenarios are supported.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119690423A_ABST
    Figure CN119690423A_ABST
Patent Text Reader

Abstract

The invention discloses an API interface development method and device, equipment and a storage medium, and relates to the technical field of software development, and the method comprises the following steps: determining API interface definition and interface implementation, storing API interface definition information and interface implementation in an interface definition table and an interface implementation table, determining a binding relationship between the API interface definition and the interface implementation, and storing the binding relationship in a binding relationship table; determining a target HTTP request, querying an API interface definition based on a request path, determining target interface implementation, and loading the target interface implementation to a memory; calling a preprocessor to process an original request parameter of the target HTTP request to obtain a processed request parameter, and executing processing logic on the processed request parameter based on the implementation mode to obtain an execution result; and processing the execution result by using a rear processor to obtain a target processing result, and obtaining an HTTP response object according to the target processing result and sending the HTTP response object to the calling party. The flexibility and expansibility of the interface can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of software development technology, and in particular to an API interface development method, device, equipment and storage medium. Background Art

[0002] In the prior art, the interface implementation solutions that are closest to or similar to the present invention mainly include two types: one is the traditional development model based on static binding, and the other is the enterprise-level service bus architecture.

[0003] In traditional software development, the relationship between an interface and its implementation class is usually determined at compile time, which is called static binding. Developers will explicitly specify the implementation class of the interface and directly reference it in the code. For example, in the Java programming language, the implementation class of the interface is explicitly declared using the implements keyword, and the specific implementation object is instantiated using the new keyword when the program is running. In this mode, the implementation of the interface is fixed and lacks flexibility.

[0004] As a core middleware architecture, ESB (Enterprise Service Bus) achieves seamless integration and efficient communication between heterogeneous systems by providing unified service interfaces, message routing, conversion, and security control mechanisms. The advantages of ESB lie in its powerful service governance capabilities and flexible message processing capabilities, which can support complex enterprise-level application integration scenarios. However, with the continuous changes in business needs and the continuous advancement of technology, the limitations of ESB in interface synchronization and adaptive configuration have gradually emerged.

[0005] In summary, how to improve the flexibility and scalability of the interface is a problem that needs to be solved urgently. Summary of the invention

[0006] In view of this, the purpose of the present invention is to provide an API interface development method, device, equipment and storage medium, which can improve the flexibility and scalability of the interface. The specific scheme is as follows:

[0007] In a first aspect, the present application provides an API interface development method, comprising:

[0008] Determine the API interface definition and the corresponding interface implementation based on the API creation request, save the corresponding API interface definition information into the interface definition table, save the interface implementation into the interface implementation table, determine the binding relationship between the API interface definition and the interface implementation, and save the binding relationship into the binding relationship table; wherein the interface implementation includes an implementation method, a pre-processor, and a post-processor;

[0009] Determine the target HTTP request by using the HTTP server and the interceptor, and query the corresponding API interface definition in the interface definition table based on the request path in the target HTTP request, determine the corresponding target interface implementation from the interface implementation table according to the queried API interface definition and the binding relationship table, and load the target interface implementation into the memory;

[0010] Calling the preprocessor in the target interface implementation through the interceptor to process the original request parameters of the target HTTP request to obtain processed request parameters, and executing corresponding processing logic on the processed request parameters based on the implementation method in the target interface implementation to obtain corresponding execution results;

[0011] The execution result is processed by the postprocessor in the target interface implementation to obtain a target processing result, a corresponding HTTP response object is obtained according to the target processing result, and the HTTP response object is sent to the caller to complete the API interface development.

[0012] Optionally, the API interface definition includes interface name, request path, interface description, request method, request parameters and response type.

[0013] Optionally, the determining the target HTTP request by using the HTTP server and the interceptor includes:

[0014] The HTTP server is used to monitor and receive the HTTP request sent by the caller, and the HTTP request sent by the caller is filtered through the interceptor to obtain the target HTTP request.

[0015] Optionally, after the target interface implementation is loaded into the memory, the method further includes:

[0016] The threads in which different callers call the target interface implementation are stored in thread local variables, so that the corresponding target processing results obtained by different callers in the process of calling the target interface implementation are determined through the thread local variables.

[0017] Optionally, the implementation method includes database query, HTTP call, network service call, and custom script.

[0018] Optionally, executing corresponding processing logic on the processed request parameter based on the implementation mode in the target interface implementation to obtain a corresponding execution result includes:

[0019] If the implementation method in the target interface implementation is the database query, constructing and executing a structured query language, querying the processed request parameters through the structured query language to obtain a query result, and encapsulating the query result as the corresponding execution result;

[0020] If the implementation method in the target interface implementation is the HTTP call, sending a request to the HTTP address in the processed request parameter, and receiving the corresponding execution result;

[0021] If the implementation method in the target interface implementation is the network service call, calling the preset network service interface to obtain the corresponding execution result;

[0022] If the implementation method in the target interface implementation is the custom script, the preset code logic is directly loaded and executed to obtain the corresponding execution result.

[0023] Optionally, obtaining a corresponding HTTP response object according to the target processing result includes:

[0024] If the target processing result indicates that the processing is normal, then obtaining the corresponding preset correct HTTP status code, preset response header and preset response body;

[0025] If the target processing result indicates that the processing has failed, a corresponding preset error status code and preset error information are obtained.

[0026] In a second aspect, the present application provides an API interface development device, comprising:

[0027] An interface definition and implementation binding module, used to determine the API interface definition and the corresponding interface implementation based on the API creation request, save the corresponding API interface definition information into the interface definition table, save the interface implementation into the interface implementation table, determine the binding relationship between the API interface definition and the interface implementation, and save the binding relationship into the binding relationship table; wherein the interface implementation includes an implementation method, a pre-processor and a post-processor;

[0028] An interface definition determination module is used to determine a target HTTP request using an HTTP server and an interceptor, and query the corresponding API interface definition in the interface definition table based on the request path in the target HTTP request, determine the corresponding target interface implementation from the interface implementation table according to the queried API interface definition and the binding relationship table, and load the target interface implementation into the memory;

[0029] An execution result acquisition module, used for invoking the preprocessor in the target interface implementation through the interceptor to process the original request parameters of the target HTTP request to obtain processed request parameters, and executing corresponding processing logic on the processed request parameters based on the implementation method in the target interface implementation to obtain corresponding execution results;

[0030] The API interface development completion module is used to use the post-processor in the target interface implementation to process the execution result to obtain the target processing result, obtain the corresponding HTTP response object according to the target processing result, and send the HTTP response object to the caller to complete the API interface development.

[0031] In a third aspect, the present application provides an electronic device, including:

[0032] Memory, used to store computer programs;

[0033] The processor is used to execute the computer program to implement the API interface development method as described above.

[0034] In a fourth aspect, the present application provides a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, the API interface development method as described above is implemented.

[0035] In summary, the present application first determines the API interface definition and the corresponding interface implementation based on the API creation request, saves the corresponding API interface definition information into the interface definition table, saves the interface implementation into the interface implementation table, determines the binding relationship between the API interface definition and the interface implementation, and saves the binding relationship into the binding relationship table; wherein the interface implementation includes an implementation method, a preprocessor, and a postprocessor; uses an HTTP server and an interceptor to determine the target HTTP request, and queries the corresponding API interface definition in the interface definition table based on the request path in the target HTTP request; and queries the corresponding API interface definition according to the queried API interface definition and the postprocessor. The binding relationship table determines the corresponding target interface implementation from the interface implementation table, and loads the target interface implementation into the memory; calls the preprocessor in the target interface implementation through the interceptor to process the original request parameters of the target HTTP request to obtain processed request parameters, and executes corresponding processing logic on the processed request parameters based on the implementation method in the target interface implementation to obtain corresponding execution results; uses the postprocessor in the target interface implementation to process the execution result to obtain the target processing result, obtains the corresponding HTTP response object according to the target processing result, and sends the HTTP response object to the caller to complete the API interface development. It can be concluded that the present application first creates a corresponding API interface definition and interface implementation based on the obtained API creation request, and stores the created API interface definition and interface implementation in an interface definition table and an interface implementation table respectively, wherein the interface implementation includes an implementation method, a preprocessor and a postprocessor. Next, the API interface definition and the corresponding interface implementation are bound, and the binding relationship between the API interface definition and the corresponding interface implementation is stored in a binding relationship table. Then, the target HTTP request is identified and located using an HTTP server and an interceptor, and a query is performed in the interface definition table according to the request path in the target HTTP request to obtain a matching API interface definition. Subsequently, the interface implementation corresponding to the obtained API interface definition is determined with the help of the constructed binding relationship table and the interface implementation table, and the determined interface implementation is loaded into the memory. When the target HTTP request enters the processing flow, the preprocessor of the target interface implementation is called through the interceptor, and the original request parameters of the target HTTP request are processed to generate processed request parameters. Based on the implementation method of the target interface implementation, the corresponding processing logic is strictly executed for the processed request parameters to obtain the execution result. The execution result is further processed by the post-processor implemented by the target interface to obtain the final target processing result. According to the target processing result, the corresponding HTTP response object is obtained, and the HTTP response object is sent to the caller to complete the full process of API interface development.In this way, the interface definition is stored in the database, real-time interface modification and hot interface update are realized, the scalability of the interface is improved, and the interface implementation is abstracted into modules such as pre-processor, implementation method, and post-processor, realizing the standardized process of the interface and the flexibility of interface logic modification. BRIEF DESCRIPTION OF THE DRAWINGS

[0036] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.

[0037] Figure 1 A flow chart of an API interface development method disclosed in the present invention;

[0038] Figure 2 A schematic diagram of a specific API interface development method disclosed in the present invention;

[0039] Figure 3 This is a schematic diagram of the structure of an API interface development device disclosed in the present invention;

[0040] Figure 4 The present invention is a structural diagram of an electronic device disclosed in the present invention. DETAILED DESCRIPTION

[0041] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0042] At present, in traditional software development, the relationship between an interface and its implementation class is usually determined at compile time, which is called static binding. Developers will explicitly specify the implementation class of the interface and directly reference it in the code. For example, in the Java programming language, the implementation class of the interface is explicitly declared through the implements keyword, and the specific implementation object is instantiated through the new keyword when the program is running. In this mode, the implementation of the interface is fixed and lacks flexibility. As a core middleware architecture, ESB (Enterprise Service Bus) realizes seamless integration and efficient communication between heterogeneous systems by providing unified service interfaces, message routing, conversion and security control mechanisms. The advantage of ESB lies in its powerful service governance capabilities and flexible message processing capabilities, which can support complex enterprise-level application integration scenarios. However, with the continuous changes in business needs and the continuous advancement of technology, the limitations of ESB in interface synchronization and adaptive configuration have gradually emerged. In order to solve the above technical problems, the present application discloses an API interface development method, device, equipment and storage medium, which can improve the flexibility and scalability of the interface.

[0043] See also Figure 1 As shown, the embodiment of the present invention discloses an API interface development method, including:

[0044] Step S11, based on the API creation request, respectively determine the API interface definition and the corresponding interface implementation, save the corresponding API interface definition information into the interface definition table, save the interface implementation into the interface implementation table, determine the binding relationship between the API interface definition and the interface implementation, and save the binding relationship into the binding relationship table; wherein, the interface implementation includes an implementation method, a pre-processor and a post-processor.

[0045] In this embodiment, during the API development process, it is first necessary to determine the API interface definition and store the API interface definition in the interface definition table of the database. Among them, the API interface definition includes the interface name, request path (URL), interface description, request method, request parameters and response type. After determining the API interface definition, the corresponding interface implementation is written according to the determined API interface definition, and the interface implementation is stored in the interface implementation table of the database, wherein the interface implementation includes a preprocessor, a postprocessor and an implementation method. The implementation method is used to implement the various functions and services declared in the interface definition; the preprocessor is responsible for the preliminary processing of the data entering the system to ensure that these original requests have been tested for validity and meet the necessary format requirements before being submitted to the internal processing flow; the postprocessor is responsible for further optimizing or adjusting the results obtained after the calculation is completed to ensure that it can meet the expected format standards or improve the security of the information. After determining the API interface definition and the corresponding interface implementation, the API interface definition and the corresponding interface implementation are bound, and the binding relationship between the API interface definition and the corresponding interface implementation is stored in the binding relationship table of the database.

[0046] In a specific implementation, firstly, the interface definition information such as the interface name, request path, interface description, request method (GET / POST), request parameters and response type is entered on the Web page, and the interface definition information is stored in the interface definition table of the database. Then, the interface implementation is entered on the Web page, and the interface implementation information includes the implementation method, pre-processor and post-processor, and the interface implementation is stored in the interface implementation table of the database. Finally, the interface definition and the interface implementation are bound on the Web page, and the binding relationship between the interface definition and the interface implementation is stored in the database binding relationship table.

[0047] Step S12: Use the HTTP server and the interceptor to determine the target HTTP request, and query the corresponding API interface definition in the interface definition table based on the request path in the target HTTP request, determine the corresponding target interface implementation from the interface implementation table according to the queried API interface definition and the binding relationship table, and load the target interface implementation into the memory.

[0048] In this embodiment, after completing the preparation work such as determining the API interface definition, the corresponding interface implementation, and the binding relationship between the API interface definition and the corresponding interface implementation, the HTTP server is used to monitor and receive the HTTP request sent by the caller, and the HTTP request sent by the caller is filtered through the interceptor to obtain the target HTTP request. In a specific implementation, an HTTP server, such as Tomcat, is used. When the HTTP server is running, it monitors the network connection request from the outside on the port. When the client initiates an HTTP request to the server through the network, the HTTP server is responsible for receiving these HTTP requests and forwarding these HTTP requests to the Servlet (usually referring to the controller or Controller layer) in the application. The HTTP request sent by the caller is filtered to obtain the target HTTP request, the URL and necessary request parameters in the target HTTP request are extracted, and the corresponding interface definition is queried from the interface definition table of the database according to the URL in the target HTTP request. The binding relationship corresponding to the queried interface definition is determined in the binding relationship table according to the queried interface definition, and then the corresponding target interface implementation is determined in the interface implementation table according to the binding relationship. Finally, the target interface implementation is loaded into the memory.

[0049] In this embodiment, after the target interface implementation is loaded into the memory, the threads of different callers calling the target interface implementation are also stored in thread local variables, so that the corresponding target processing results obtained by different callers in the process of calling the target interface implementation can be determined through thread local variables. Specifically, after the target interface implementation is loaded into the memory, specific thread management operations are carried out for different callers. When each caller calls the target interface implementation, a corresponding thread will be generated. These threads will be stored in special thread local variables. Since the operations of different callers are independent of each other, the generated threads are also independent. By storing these threads in thread local variables, each caller can be clearly traced back based on the thread local variables, and the target processing results obtained by each caller can also be accurately determined, thereby ensuring the orderliness of the entire calling process and the traceability of the results.

[0050] Step S13, calling the preprocessor in the target interface implementation through the interceptor to process the original request parameters of the target HTTP request to obtain processed request parameters, and executing corresponding processing logic on the processed request parameters based on the implementation method in the target interface implementation to obtain corresponding execution results.

[0051] In this embodiment, the preprocessor in the target interface implementation is first called with the help of an interceptor. The preprocessor receives the original request parameters carried by the target HTTP request and uses preset rules and algorithms to deeply analyze and process these original data. For example, operations such as data format conversion, data cleaning and verification are performed to obtain processed request parameters. Then, according to the implementation method set in the target interface implementation, the processed request parameters are imported into the corresponding processing logic module. This module performs a series of operations such as calculation, data association and integration on the processed request parameters based on the preset business logic. Finally, the corresponding execution result is obtained.

[0052] Further, the implementation method includes database query, HTTP call, network service call, and custom script. If the implementation method in the target interface implementation is database query, then construct and execute structured query language, query the processed request parameters through structured query language to obtain query results, and encapsulate the query results as corresponding execution results; if the implementation method in the target interface implementation is HTTP call, send a request to the HTTP address in the processed request parameters, and receive the corresponding execution results; if the implementation method in the target interface implementation is network service call, call the preset network service interface to obtain the corresponding execution results; if the implementation method in the target interface implementation is a custom script, directly load and execute the preset code logic to obtain the corresponding execution results. Specifically, according to the implementation method specified in the interface configuration, dynamically select and execute the processing logic in the target interface implementation. If the implementation method is database query, construct and execute SQL statements, query data from the database, and encapsulate the results into an appropriate format. If the implementation method is HTTP call, use tools such as HttpClient to send requests to the configured HTTP address, and receive and process responses. If the implementation method is a WebService call, the JAX-WS technology can be used to call the specified WebService interface and process the returned SOAP message. If the implementation method is custom code, the configured Java code logic is directly loaded and executed, where the Java code logic contains business processing or data processing algorithms.

[0053] Step S14: Use the postprocessor in the target interface implementation to process the execution result to obtain a target processing result, obtain a corresponding HTTP response object according to the target processing result, and send the HTTP response object to the caller to complete the API interface development.

[0054] In this embodiment, after obtaining the execution result, the postprocessor in the target interface implementation is used to further process the execution result. The postprocessor will process the execution result according to the pre-set rules and logic, and convert the execution result into the target processing result. Subsequently, based on the specific content of the target processing result, the corresponding HTTP response object is obtained. If the target processing result indicates that the processing is normal, the corresponding preset correct HTTP status code, preset response header and preset response body are obtained; if the target processing result indicates that the processing fails, the corresponding preset error status code and preset error information are obtained. Specifically, when the target processing result indicates that the processing process is normal and completed smoothly, the corresponding preset correct HTTP status code, preset response header and preset response body are obtained. If the target processing result indicates that the processing fails, the system will instead obtain the corresponding preset error status code and preset error information. The preset error information can describe the cause of the error, feasible solution suggestions or relevant information that helps the caller to troubleshoot the problem, so that the caller can quickly locate the problem and take corresponding measures to repair or adjust the subsequent operation strategy after receiving the error response. Finally, the constructed HTTP response object is sent to the caller. At this point, the entire API interface development process has been successfully completed, providing the caller with a stable, reliable and fully functional API service, meeting the data interaction and function call requirements in different business scenarios.

[0055] It can be concluded that the present application first creates a corresponding API interface definition and interface implementation based on the obtained API creation request, and stores the created API interface definition and interface implementation in an interface definition table and an interface implementation table respectively, wherein the interface implementation includes an implementation method, a preprocessor and a postprocessor. Next, the API interface definition and the corresponding interface implementation are bound, and the binding relationship between the API interface definition and the corresponding interface implementation is stored in a binding relationship table. Then, the target HTTP request is identified and located using an HTTP server and an interceptor, and a query is performed in the interface definition table according to the request path in the target HTTP request to obtain a matching API interface definition. Subsequently, the interface implementation corresponding to the obtained API interface definition is determined with the help of the constructed binding relationship table and the interface implementation table, and the determined interface implementation is loaded into the memory. When the target HTTP request enters the processing flow, the preprocessor of the target interface implementation is called through the interceptor, and the original request parameters of the target HTTP request are processed to generate processed request parameters. Based on the implementation method of the target interface, the corresponding processing logic is strictly executed for the request parameters after processing, and then the execution result is obtained. The execution result is further processed by the post-processor of the target interface implementation to obtain the final target processing result. According to the target processing result, the corresponding HTTP response object is obtained, and the HTTP response object is sent to the caller to complete the full process of API interface development. In this way, the interface definition is stored in the database, and real-time interface modification and hot interface update are realized, the scalability of the interface is improved, and the interface implementation is abstracted into modules such as pre-processor, implementation method, and post-processor, realizing the standardized process of the interface and the flexibility of interface logic modification.

[0056] Based on the above embodiment, it can be seen that the present application discloses an API interface development method, which can improve the flexibility and scalability of the interface. In addition, the present application provides an interface execution template for interface implementation, including a preprocessor, an implementation method, and a postprocessor. Figure 2 The specific API interface development method and interface execution template shown are explained in detail.

[0057] This application first determines the API interface definition, and stores the API interface definition in the interface definition table of the database, writes the corresponding interface implementation according to the determined API interface definition, and stores the interface implementation in the interface implementation table of the database, binds the API interface definition and the corresponding interface implementation, and stores the binding relationship between the API interface definition and the corresponding interface implementation in the binding relationship table of the database. After completing the preparatory work such as determining the API interface definition, the corresponding interface implementation, and the binding relationship between the API interface definition and the corresponding interface implementation, the HTTP server is used to monitor and receive the HTTP request sent by the caller, and the HTTP request sent by the caller is filtered through the interceptor to obtain the target HTTP request. According to the URL in the target HTTP request, the corresponding interface definition is queried from the interface definition table of the database, and the binding relationship corresponding to the queried interface definition is determined in the binding relationship table according to the queried interface definition, and then the corresponding target interface implementation is determined in the interface implementation table according to the binding relationship, and finally, the target interface implementation is loaded into the memory. Then, with the help of the interceptor, the preprocessor in the interface execution template corresponding to the target interface is called. If the preprocessor is a custom code snippet, the script engine such as Groovy Shell can be used to dynamically compile and execute these codes; if the preprocessor is a specified internal class, the JAVA reflection technology is used to call the system internal class, and the processed request parameters are returned after the processing is completed. Then, according to the implementation method set in the target interface implementation, the implementation method includes database query, HTTP call, network service call, and custom script, the processed request parameters are imported into the corresponding processing logic module to obtain the corresponding execution result. After obtaining the execution result, the postprocessor in the interface execution template corresponding to the target interface is used to process the execution result. The specific implementation method of the postprocessor to process the execution result is the same as that of the preprocessor, which will not be repeated here, and the execution result is finally converted into the target processing result. Subsequently, based on the specific content of the target processing result, the corresponding HTTP response object is obtained, and finally, the constructed HTTP response object is sent to the caller. At this point, the entire API interface development process is successfully completed.

[0058] See also Figure 3 As shown, the embodiment of the present invention discloses an API interface development device, including:

[0059] The interface definition and implementation binding module 11 is used to determine the API interface definition and the corresponding interface implementation based on the API creation request, save the corresponding API interface definition information into the interface definition table, save the interface implementation into the interface implementation table, determine the binding relationship between the API interface definition and the interface implementation, and save the binding relationship into the binding relationship table; wherein the interface implementation includes an implementation method, a pre-processor and a post-processor;

[0060] The interface definition determination module 12 is used to determine the target HTTP request by using the HTTP server and the interceptor, and query the corresponding API interface definition in the interface definition table based on the request path in the target HTTP request, determine the corresponding target interface implementation from the interface implementation table according to the queried API interface definition and the binding relationship table, and load the target interface implementation into the memory;

[0061] An execution result acquisition module 13 is used to call the preprocessor in the target interface implementation through the interceptor to process the original request parameters of the target HTTP request to obtain processed request parameters, and execute corresponding processing logic on the processed request parameters based on the implementation method in the target interface implementation to obtain corresponding execution results;

[0062] The API interface development completion module 14 is used to use the post-processor in the target interface implementation to process the execution result to obtain the target processing result, obtain the corresponding HTTP response object according to the target processing result, and send the HTTP response object to the caller to complete the API interface development.

[0063] It can be concluded that the present application first creates a corresponding API interface definition and interface implementation based on the obtained API creation request, and stores the created API interface definition and interface implementation in an interface definition table and an interface implementation table respectively, wherein the interface implementation includes an implementation method, a preprocessor and a postprocessor. Next, the API interface definition and the corresponding interface implementation are bound, and the binding relationship between the API interface definition and the corresponding interface implementation is stored in a binding relationship table. Then, the target HTTP request is identified and located using an HTTP server and an interceptor, and a query is performed in the interface definition table according to the request path in the target HTTP request to obtain a matching API interface definition. Subsequently, the interface implementation corresponding to the obtained API interface definition is determined with the help of the constructed binding relationship table and the interface implementation table, and the determined interface implementation is loaded into the memory. When the target HTTP request enters the processing flow, the preprocessor of the target interface implementation is called through the interceptor, and the original request parameters of the target HTTP request are processed to generate processed request parameters. Based on the implementation method of the target interface, the corresponding processing logic is strictly executed for the request parameters after processing, and then the execution result is obtained. The execution result is further processed by the post-processor of the target interface implementation to obtain the final target processing result. According to the target processing result, the corresponding HTTP response object is obtained, and the HTTP response object is sent to the caller to complete the full process of API interface development. In this way, the interface definition is stored in the database, and real-time interface modification and hot interface update are realized, the scalability of the interface is improved, and the interface implementation is abstracted into modules such as pre-processor, implementation method, and post-processor, realizing the standardized process of the interface and the flexibility of interface logic modification.

[0064] In some specific embodiments, the interface definition determination module 12 may specifically include:

[0065] The target HTTP request acquisition unit is used to use the HTTP server to monitor and receive the HTTP request sent by the caller, and filter the HTTP request sent by the caller through the interceptor to obtain the target HTTP request.

[0066] In some specific embodiments, the API interface development device may further include:

[0067] The target processing result acquisition module is used to store the threads of different callers calling the target interface implementation into thread local variables, so as to determine the corresponding target processing results obtained by different callers in the process of calling the target interface implementation through the thread local variables.

[0068] In some specific embodiments, the execution result acquisition module 13 may specifically include:

[0069] A first execution result acquisition unit is used for constructing and executing a structured query language if the implementation method in the target interface implementation is the database query, querying the processed request parameters through the structured query language to obtain a query result, and encapsulating the query result as the corresponding execution result;

[0070] A second execution result obtaining unit, configured to send a request to the HTTP address in the processed request parameter and receive the corresponding execution result if the implementation method in the target interface implementation is the HTTP call;

[0071] A third execution result acquisition unit, configured to call a preset network service interface to obtain the corresponding execution result if the implementation method in the target interface implementation is the network service call;

[0072] The fourth execution result acquisition unit is used to directly load and execute the preset code logic to obtain the corresponding execution result if the implementation method in the target interface implementation is the custom script.

[0073] In some specific embodiments, the API interface development completion module 14 may specifically include:

[0074] A first target processing result judgment unit, configured to obtain a corresponding preset correct HTTP status code, a preset response header, and a preset response body if the target processing result indicates that the processing is normal;

[0075] The second target processing result judgment unit is used to obtain a corresponding preset error status code and preset error information if the target processing result indicates that the processing fails.

[0076] Furthermore, the present application also discloses an electronic device. Figure 4 This is a structural diagram of an electronic device 20 according to an exemplary embodiment. The content in the diagram cannot be regarded as any limitation on the scope of use of the present application.

[0077] Figure 4A schematic diagram of the structure of an electronic device 20 provided in an embodiment of the present application. The electronic device 20 may specifically include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input / output interface 25, and a communication bus 26. The memory 22 is used to store a computer program, which is loaded and executed by the processor 21 to implement the relevant steps in the API interface development method disclosed in any of the aforementioned embodiments. In addition, the electronic device 20 in this embodiment may specifically be an electronic computer.

[0078] In this embodiment, the power supply 23 is used to provide working voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and the external device, and the communication protocol it follows is any communication protocol that can be applied to the technical solution of the present application, and is not specifically limited here; the input and output interface 25 is used to obtain external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs and is not specifically limited here.

[0079] In addition, the memory 22, as a carrier for storing resources, can be a read-only memory, a random access memory, a disk or an optical disk, etc. The resources stored thereon can include an operating system 221, a computer program 222, etc., and the storage method can be temporary storage or permanent storage.

[0080] The operating system 221 is used to manage and control the hardware devices and computer program 222 on the electronic device 20, which can be Windows Server, Netware, Unix, Linux, etc. In addition to including a computer program that can be used to complete the API interface development method executed by the electronic device 20 disclosed in any of the aforementioned embodiments, the computer program 222 can further include a computer program that can be used to complete other specific tasks.

[0081] Furthermore, the present application also discloses a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, the aforementioned disclosed API interface development method is implemented. The specific steps of the method can refer to the corresponding contents disclosed in the aforementioned embodiments, and will not be repeated here.

[0082] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part.

[0083] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.

[0084] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be implemented directly using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.

[0085] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.

[0086] The technical solution provided by the present application is introduced in detail above. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea. At the same time, for general technicians in this field, according to the idea of ​​the present application, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.

Claims

1. An API interface development method, characterized in that: include: Determine the API interface definition and the corresponding interface implementation based on the API creation request, save the corresponding API interface definition information into the interface definition table, save the interface implementation into the interface implementation table, determine the binding relationship between the API interface definition and the interface implementation, and save the binding relationship into the binding relationship table; wherein the interface implementation includes an implementation method, a pre-processor, and a post-processor; Determine the target HTTP request by using the HTTP server and the interceptor, and query the corresponding API interface definition in the interface definition table based on the request path in the target HTTP request, determine the corresponding target interface implementation from the interface implementation table according to the queried API interface definition and the binding relationship table, and load the target interface implementation into the memory; Calling the preprocessor in the target interface implementation through the interceptor to process the original request parameters of the target HTTP request to obtain processed request parameters, and executing corresponding processing logic on the processed request parameters based on the implementation method in the target interface implementation to obtain corresponding execution results; The execution result is processed by the postprocessor in the target interface implementation to obtain a target processing result, a corresponding HTTP response object is obtained according to the target processing result, and the HTTP response object is sent to the caller to complete the API interface development.

2. The API interface development method according to claim 1, characterized in that: The API interface definition includes interface name, request path, interface description, request method, request parameters and response type.

3. The API interface development method according to claim 1, characterized in that: Determining the target HTTP request by using the HTTP server and the interceptor includes: The HTTP server is used to monitor and receive the HTTP request sent by the caller, and the HTTP request sent by the caller is filtered through the interceptor to obtain the target HTTP request.

4. The API interface development method according to claim 1, characterized in that: After the target interface is loaded into the memory, the method further includes: The threads in which different callers call the target interface implementation are stored in thread local variables, so that the corresponding target processing results obtained by different callers in the process of calling the target interface implementation are determined through the thread local variables.

5. The API interface development method according to any one of claims 1 to 4, characterized in that: The implementation methods include database query, HTTP call, network service call, and custom script.

6. The API interface development method according to claim 5, characterized in that: The executing corresponding processing logic on the processed request parameter based on the implementation mode in the target interface implementation to obtain a corresponding execution result includes: If the implementation method in the target interface implementation is the database query, constructing and executing a structured query language, querying the processed request parameters through the structured query language to obtain a query result, and encapsulating the query result as the corresponding execution result; If the implementation method in the target interface implementation is the HTTP call, sending a request to the HTTP address in the processed request parameter, and receiving the corresponding execution result; If the implementation method in the target interface implementation is the network service call, calling the preset network service interface to obtain the corresponding execution result; If the implementation method in the target interface implementation is the custom script, the preset code logic is directly loaded and executed to obtain the corresponding execution result.

7. The API interface development method according to claim 1, characterized in that: The obtaining a corresponding HTTP response object according to the target processing result includes: If the target processing result indicates that the processing is normal, then obtaining the corresponding preset correct HTTP status code, preset response header and preset response body; If the target processing result indicates that the processing has failed, a corresponding preset error status code and preset error information are obtained.

8. An API interface development device, characterized in that: include: An interface definition and implementation binding module, used to determine the API interface definition and the corresponding interface implementation based on the API creation request, save the corresponding API interface definition information into the interface definition table, save the interface implementation into the interface implementation table, determine the binding relationship between the API interface definition and the interface implementation, and save the binding relationship into the binding relationship table; wherein the interface implementation includes an implementation method, a pre-processor and a post-processor; An interface definition determination module is used to determine a target HTTP request using an HTTP server and an interceptor, and query the corresponding API interface definition in the interface definition table based on the request path in the target HTTP request, determine the corresponding target interface implementation from the interface implementation table according to the queried API interface definition and the binding relationship table, and load the target interface implementation into the memory; An execution result acquisition module, used for invoking the preprocessor in the target interface implementation through the interceptor to process the original request parameters of the target HTTP request to obtain processed request parameters, and executing corresponding processing logic on the processed request parameters based on the implementation method in the target interface implementation to obtain corresponding execution results; The API interface development completion module is used to use the post-processor in the target interface implementation to process the execution result to obtain the target processing result, obtain the corresponding HTTP response object according to the target processing result, and send the HTTP response object to the caller to complete the API interface development.

9. An electronic device, characterized in that: include: Memory, used to store computer programs; A processor, used to execute the computer program to implement the API interface development method as described in any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that: Used to store a computer program; wherein, when the computer program is executed by a processor, the API interface development method as described in any one of claims 1 to 7 is implemented.

Citation Information

Patent Citations

  • Method and device for invoking performance function

    CN101620536A

  • Control method of hyper text transport protocol (HTTP) demand processing

    CN103067511A

  • Processing method and device for achieving API calling and system for achieving API

    CN109739573A

  • Request data verification result prompting method and device, storage medium and equipment

    CN115277187A

  • Target protocol request processing method and device, electronic equipment and storage medium

    CN115996246A

Cited By

  • Plug-in-based front-end page rendering method and system

    CN120909588A