Interface processing method, device and system and computer storage medium
By obtaining the API implementation code of the back-end development platform, generating preset codes and sending parameter information, the problem of inconsistent front-end and back-end interface standards is solved, the efficiency of network business development is improved, and the workload of interface joint debugging is reduced.
Patent Information
- Application Number
- CN202410974364.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-19
- Publication Date
- 2024-10-15
AI Technical Summary
The inconsistent front-end and back-end interface standards lead to low efficiency in network business development, which requires frequent interface joint debugging, making development more difficult and time-consuming.
By obtaining the API implementation code compiled by the back-end development platform, determine the interface annotation information, generate the preset code, call the preset code to generate the API of the target structure, and send the parameter information to the front-end development platform to ensure that the front-end and back-end interfaces are consistent and reduce the number of interfaces Joint debugging workload.
It significantly reduces the workload of interface joint debugging, improves the efficiency of network business development, ensures the unification of front-end and back-end interfaces, and reduces the workload and development time of back-end developers.
Smart Images

Figure CN118778937A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of interface alignment, and in particular to an interface processing method, device, system and computer storage medium. Background Art
[0002] With the development of network business, the requirements for the interactive experience and response experience of the front-end page are getting higher and higher, and the performance requirements for back-end services are also getting higher and higher. Therefore, the professional requirements for front-end developers and back-end developers when developing business are also getting higher.
[0003] Since there is no standard specification of API (Application Programming Interface) between the front-end and the back-end, both front-end developers and back-end developers develop business according to their own habits, which will cause the problem of inconsistent interface standards between the front-end and the back-end.
[0004] Due to the lack of unified interface standards between the front-end and back-end, interface mismatch may occur, resulting in the inability to implement network service functions normally. In order to avoid interface mismatch, the front-end and back-end need to frequently perform interface joint debugging, and determine the interface matching during the interface joint debugging process. With the increase in interface professional requirements, the workload of interface joint debugging will increase, and the time and difficulty of network service development will also increase, which seriously affects the efficiency of network service development. Summary of the invention
[0005] The present application provides an interface processing method, device, system and computer storage medium to solve the technical problem in the prior art that the front-end and back-end interface standards are not unified, resulting in low efficiency in network business development, thereby reducing the workload of interface joint debugging and improving the efficiency of network business development.
[0006] In a first aspect, the present application provides an interface processing method, comprising:
[0007] Obtaining the implementation code of the application programming interface API compiled by the back-end development platform, wherein the implementation code is the interface code of the API, which is used to generate the API of the target structure, and the status of the implementation code is that the compilation is not completed;
[0008] Determining interface annotation information in the implementation code;
[0009] Determine and generate a corresponding preset code according to the interface annotation information;
[0010] Calling the preset code to generate the API of the target structure;
[0011] Determine parameter information of the API, and send the parameter information to a front-end development platform to display the parameter information.
[0012] Optionally, after sending the parameter information to the front-end development platform, the method further includes:
[0013] Acquire the target operation received by the front-end development platform, and determine the query instruction corresponding to the target operation, wherein the target operation is used to query the target parameter in the parameter information;
[0014] Based on the parameter information received by the front-end development platform, a target parameter corresponding to the query instruction is obtained, and the target parameter is sent to the front-end development platform to display the target parameter.
[0015] Optionally, determining interface annotation information in the implementation code, and generating a corresponding preset code according to the interface annotation information includes:
[0016] Determine the comment start position and comment end position in the implementation code by using the algorithm format of the implementation code;
[0017] Based on the data between the comment start bit and the comment end bit, the interface comment information is obtained;
[0018] Parsing the interface annotation information using a preset data structure to obtain the structure information of the API, wherein the preset data structure is a preset annotation compilation structure;
[0019] The preset code is generated based on the structural information of the API.
[0020] Optionally, the method further comprises:
[0021] Obtaining the scheduled tasks sent by the backend development platform;
[0022] Determine the execution frequency and execution cycle duration of the scheduled task;
[0023] According to the execution frequency and the execution cycle duration, the step of obtaining the implementation code of the API compiled by the back-end development platform is periodically performed.
[0024] Optionally, after sending the parameter information to the front-end development platform, the method further includes:
[0025] When a development request from the front-end development platform is obtained, back-end debugging data is obtained, wherein the back-end debugging data is data generated when the back-end development platform debugs the API;
[0026] Generate corresponding simulation data mock according to the backend debugging data;
[0027] The mock is sent to the front-end development platform.
[0028] Optionally, after sending the mock to the front-end development platform, the method further includes:
[0029] Acquire front-end development data, wherein the front-end development data is data generated when the front-end development platform develops the API;
[0030] Generate a test case for the API based on the backend debugging data and the frontend development data;
[0031] When a test instruction is received, the test case is called to test the function of the API to obtain the test result of the API.
[0032] Optionally, the method further comprises:
[0033] When the test result is abnormal, determining the execution order of tasks in the test case;
[0034] Testing the tasks in the test case in sequence according to the task execution order;
[0035] When it is detected that the task is abnormal, the function of the API is abnormal, and the task with the abnormality is displayed.
[0036] In a second aspect, the present application further provides an interface processing device, including:
[0037] at least one communication interface; at least one bus connected to the at least one communication interface; at least one processor connected to the at least one bus; at least one memory connected to the at least one bus, wherein the processor is configured to:
[0038] Obtaining the implementation code of the application programming interface API compiled by the back-end development platform, wherein the implementation code is the interface code of the API, which is used to generate the API of the target structure, and the status of the implementation code is that the compilation is not completed;
[0039] Determining interface annotation information in the implementation code;
[0040] Determine and generate a corresponding preset code according to the interface annotation information;
[0041] Calling the preset code to generate the API of the target structure;
[0042] Determine parameter information of the API, and send the parameter information to the front-end development platform.
[0043] In a third aspect, the present application also provides an interface processing system, including:
[0044] A code acquisition unit, used to acquire the implementation code of the application programming interface API compiled by the back-end development platform, wherein the implementation code is used to generate the API of the target structure and has not been compiled;
[0045] An annotation acquisition unit, used to determine the interface annotation information in the implementation code;
[0046] A code generating unit, used to generate a corresponding preset code according to the interface annotation information;
[0047] A code calling unit, used for calling the preset code to generate the API of the target structure;
[0048] The parameter sending unit is used to determine the parameter information of the API and send the parameter information to the front-end development platform.
[0049] In a fourth aspect, the present application also provides a computer storage medium storing computer executable instructions, wherein the computer executable instructions are used to execute any of the interface processing methods described above.
[0050] The above technical solution provided by the embodiment of the present application has the following advantages over the prior art: the method provided by the embodiment of the present application obtains the implementation code of the application programming interface API compiled by the back-end development platform, wherein the implementation code is used to generate the API of the target structure and has not been compiled, determines the interface annotation information in the implementation code, determines to generate the corresponding preset code according to the interface annotation information, calls the preset code, generates the API of the target structure, determines the parameter information of the API, and sends the parameter information to the front-end development platform to display the parameter information. In this way, the front-end can determine the API interface type debugged by the back-end, so as to develop the same type of API interface, avoid the problem of inconsistent interface standards between the front-end and the back-end, and when performing interface joint debugging between the front-end and the back-end, there is no need to detect the matching of the interface, which significantly reduces the workload of interface joint debugging and improves the efficiency of network business development. BRIEF DESCRIPTION OF THE DRAWINGS
[0051] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.
[0052] 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, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0053] One or more embodiments are exemplarily described by pictures in the corresponding drawings, and these exemplified descriptions do not constitute limitations on the embodiments. Elements with the same reference numerals in the drawings represent similar elements, and unless otherwise stated, the figures in the drawings do not constitute proportional limitations.
[0054] Figure 1 A flowchart of an interface processing method provided in an embodiment of the present application;
[0055] Figure 2 A flowchart of a method for generating a preset code provided in an embodiment of the present application;
[0056] Figure 3 A flowchart of an interface testing method provided in an embodiment of the present application;
[0057] Figure 4 A schematic diagram of a network service architecture provided in an embodiment of the present application;
[0058] Figure 5 A schematic diagram of an interface information display process provided in an embodiment of the present application;
[0059] Figure 6 A schematic diagram of a network service development process provided in an embodiment of the present application;
[0060] Figure 7 A schematic diagram of an interface development architecture provided in an embodiment of the present application;
[0061] Figure 8 A schematic diagram of the structure of an interface processing device provided by the present application;
[0062] Fig. 9 A schematic diagram of the structure of an interface processing system provided in this application. DETAILED DESCRIPTION
[0063] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.
[0064] The disclosure below provides many different embodiments or examples to implement different structures of the present invention. In order to simplify the disclosure of the present invention, the parts and settings of specific examples are described below. Of course, they are only examples, and the purpose is not to limit the present invention. In addition, the present invention can repeat reference numbers and / or letters in different examples. This repetition is for the purpose of simplification and clarity, and does not itself indicate the relationship between the various embodiments and / or settings discussed.
[0065] In order to solve the technical problem in the prior art that the front-end and back-end interface standards are not unified, resulting in low efficiency in network business development, the present application provides an interface processing method that can solve the problem of inconsistent front-end and back-end interface standards and improve the efficiency of network business development.
[0066] Please refer to Figure 1 , Figure 1 A flowchart of an interface processing method provided in an embodiment of the present application includes:
[0067] S11: Acquire the implementation code of the application programming interface API compiled by the back-end development platform, wherein the implementation code is the interface code of the API, which is used to generate the API of the target structure, and the status of the implementation code is that the compilation is not completed;
[0068] Considering that the existing technology requires back-end developers to compile the API interface code before generating the corresponding API interface, during this period, the front-end cannot obtain the information of the API interface, which leads to the stagnation of the front-end API interface development and prolongs the development time of the entire network business.
[0069] In order to improve the development efficiency of network services, in this application, the back-end developers write the API interface document into the API interface code. The API interface document contains various interface information of the API interface, such as interface type, interface name, request type and return type, etc. Because these interface information are equivalent to the unique identifier of the API interface, the correspondence between the parameter information and the API interface can be established in advance.
[0070] Specifically, writing the API interface documentation into the API interface code is equivalent to integrating the specific implementation and description documentation of the API interface into the same environment. Back-end developers need to compile the API interface documentation in the API interface code according to a specific comment format. After the development web platform obtains the API interface code, it parses the comments in the API interface code according to a specific comment format to obtain the API interface documentation. The comment format is a pre-constrained comment compilation format. The development web platform can read the data in this comment format and generate the API interface documentation based on the reading results.
[0071] Then, compilation comments are needed to describe the functions of various functions and characteristic parameters such as return values. The functions of each class also need to be described in compilation comments. On this basis, in order to help the front-end understand the code and documentation, a usage example needs to be compiled as a comment.
[0072] Please refer to Figure 5 , Figure 5 A schematic diagram of an interface information display process provided for an embodiment of the present application. After adding the document generator as a plug-in in the development web platform, the back-end developer only needs to write the API interface document into the API interface code according to a specific comment compilation format. The development web platform extracts the comment content from the API interface code according to the comment compilation format, parses the comment content to obtain the API interface document, and displays it to the front end. When the back end needs to update the interface, the back end developer only needs to update the comments in the API interface code. The development web platform regularly synchronizes the comments and updates the API interface, and displays the parameter information of the updated API interface to the front end to ensure that the interfaces between the front and back ends are consistent.
[0073] By integrating documentation and code, backend developers no longer need to maintain API interface documentation separately, but only need to maintain the code itself.
[0074] S12: Determine the interface annotation information in the implementation code;
[0075] When compiling the API interface code, the back-end developers can compile the interface comments first instead of the code itself, which is equivalent to compiling the API interface document first; then, the development web platform identifies the unique identifier of the API interface from the API interface document (that is, the interface comments), and then generates the corresponding preset code based on the correspondence between the unique identifier and the API interface, and finally automatically generates the API interface. In this way, the front-end developers can know the information of the API interface before the back-end developers start compiling the API interface code.
[0076] S13: Determine and generate a corresponding preset code according to the interface annotation information;
[0077] In order to generate code based on annotations, it is necessary to add additional functions to the development web platform where the network business is located, so that the development web platform can support functions such as adding new interfaces, deleting interfaces, modifying interfaces, and querying interface information, and it is necessary to support the parsing of schema information of various API interface specifications.
[0078] Regarding the functions of adding, deleting, modifying and checking interfaces, the backend needs to import the web framework and database to deploy and manage applications and data on the development web platform; then create a class that represents the API interface. The data types and constraints in the class need to be set according to the needs of the network business.
[0079] In this class, an identifier is set for the API interface, such as interface, and different functions are defined for different functions such as adding new interfaces, deleting interfaces, modifying interfaces, and querying interface information. For example, the function for adding new interfaces is post / interface / <interface:id>, post represents the function of adding a new interface, id represents the type of API interface to be generated, and the relationship between id and API interface can be set in advance. Similarly, the function of deleting an interface is delete / interface / <interface:id>, modify the interface function to put / interface / <interface:id>, the function to query interface information is get / interface / <interface:id>.
[0080] Regarding the function of parsing schema information, you first need to determine the interface specifications in the process of network business development, and then select some tools or libraries that can parse the schema information under this interface specification. Taking the commonly used openapi3.0 as an example, swagger parser is currently a commonly used tool for parsing openapi specifications.
[0081] It should be noted that the preset code is written based on the interface comment information. The back-end developer compiles the implementation code with comments to describe the API's functions and characteristic parameters such as return values. The comment information is compiled into the implementation code through the web development platform to generate the preset code, and then the corresponding preset code is determined based on the interface comment information. The preset code lets the front-end developer know what type of API interface is generated, so that the front-end developer can develop the API interface in advance.
[0082] By parsing the interface specification through the tool, the corresponding extended application can be generated on the development web platform. The function of the extended application is to read the definition of the API interface and generate the corresponding code, that is, the preset code mentioned above.
[0083] After the above two functions are deployed to the development web platform on the back end, the development web platform can automatically parse the schema information. Back-end developers do not need to manually upload the schema information to other websites or other platforms specifically used for parsing, which saves the workload of back-end developers.
[0084] S14: calling the preset code to generate an API of the target structure;
[0085] Based on the above content, schema information refers to a type of data that defines various attributes such as parameters, types, and formats of data. For an API interface, schema information includes the name of the API interface, the type of the API interface, and the data format of the API interface.
[0086] By pre-defining the correspondence between schema information and API interfaces, back-end developers compile schema information as interface annotation information, and the web development platform determines the preset code corresponding to the schema information based on the correspondence, and then generates the API interface. In other words, back-end developers only need to compile a statement that conforms to the format of schema information, and the platform can automatically generate the API interface after parsing the schema information.
[0087] It should be noted that the preset code is just a predefined API interface code. Although the type of the generated API interface is the same as the type of API interface required by the network business, the structure and definition of the generated API interface are fixed. It is understandable that due to the different network businesses that need to be implemented, the actual logic of the same type of API interface is also different. The actual logic of the API interface cannot be generated solely based on the interface annotations. It still needs to be based on the API interface code compiled by the back-end developers to generate a real and usable API interface.
[0088] That is to say, the purpose of generating an API interface based on interface comments is to let the front-end developer know what type of API interface is generated before the back-end developer actually compiles the API interface code, so that the front-end developer can develop the API interface in advance; there is no need to wait until the back-end developer has completed the compilation of the API interface code before telling the front-end developer, which improves the development efficiency of network services.
[0089] S15: Determine parameter information of the API, and send the parameter information to the front-end development platform.
[0090] For the backend, after the API interface is generated, the backend developers can call the API interface on the backend development platform, use the interface debugging function of the development web platform to debug the interface, and implement various backend functions required by the network business.
[0091] For the front-end, the front-end developers can subscribe to the interface dynamics of the development web platform on the front-end development platform. After the API interface is generated, the development web platform sends the parameter information of the API interface to the front-end development platform that has subscribed to the interface dynamics according to the subscription situation, so that the front-end developers can view the API interface on the front-end development platform. Please refer to Figure 4 , Figure 4 A schematic diagram of a network service architecture provided in an embodiment of the present application.
[0092] The interface processing method provided by the embodiment of the present application obtains the implementation code of the application programming interface API compiled by the back-end development platform, wherein the implementation code is used to generate the API of the target structure and has not been compiled, determines the interface annotation information in the implementation code, determines to generate the corresponding preset code according to the interface annotation information, calls the preset code, generates the API of the target structure, determines the parameter information of the API, and sends the parameter information to the front-end development platform to display the parameter information. In this way, the conversion from code to preset code is realized, so that the back-end developer only needs to update the annotations in the API interface code, the development web platform regularly synchronizes the annotations and updates the API interface, and displays the updated parameter information of the API interface to the front-end, ensuring the unification of the front-end and back-end interfaces. The back-end developer only needs to compile in a specific annotation format; and when the back-end developer has not yet started to compile the API interface code, the front-end can determine the API interface type debugged by the back-end, so as to develop the same type of API interface, avoid the problem of inconsistent interface standards between the front-end and back-end, and do not need to detect the matching of the interface when performing the front-end and back-end interface joint debugging, which significantly reduces the workload of interface joint debugging and improves the efficiency of network business development.
[0093] In an optional solution of the embodiment of the present invention, considering that when developers query parameter information related to the API interface, they usually need to enter the corresponding command code to query, and since the query cannot be made when the command code is entered incorrectly, certain requirements are placed on the technical ability and memory of the developer. In order to lower the technical threshold of the developer, the present application also provides another method:
[0094] After sending the parameter information to the front-end development platform, the method further includes:
[0095] Acquire the target operation received by the front-end development platform, and determine the query instruction corresponding to the target operation, wherein the target operation is used to query the target parameter in the parameter information;
[0096] Based on the parameter information received by the front-end development platform, a target parameter corresponding to the query instruction is obtained, and the target parameter is sent to the front-end development platform to display the target parameter.
[0097] First, determine the command code set related to the API interface, which contains the command code required to query each parameter information of the API interface; then set multiple virtual buttons on the front-end development platform, and the virtual buttons correspond to the command codes one by one. When defining the name of the virtual button, the name of the virtual button needs to reflect the characteristics of the parameter information. For example, assuming that the parameter information of the API interface is the name of the API interface, the function of the command code is to obtain the name of the API interface, and the name of the virtual button can be "Get interface name" or "Name query button", etc.
[0098] The target operation received by the front-end development platform refers to the operation of the front-end developer pressing a virtual key on the front-end development platform. After pressing the virtual key, the front-end development platform will send the information of the virtual key to the development web platform. The development web platform determines the corresponding command code (that is, the query instruction) based on the information of the virtual key, and then calls the command code to obtain the target parameters in the parameter information of the API interface, and finally returns the target parameters to the front-end development platform for the front-end developer to view.
[0099] In this way, front-end developers only need to press the keyboard once to automatically obtain the parameters required by the API interface, without having to write complex compilation command codes, which greatly reduces the technical difficulty of front-end development and enables front-end developers to easily complete the query of API interface parameters. At the same time, this method is also applicable to back-end development. Back-end developers only need to follow the same operating steps to quickly obtain the parameters required by the API interface, further simplifying the back-end development process and improving development efficiency, so that the front-end and back-end can complete tasks more easily and efficiently when developing API interfaces.
[0100] In an optional solution of the embodiment of the present invention, considering that the data formats of the development web platform are different, the algorithm formats of different API interfaces are also different, and the annotation identifiers corresponding to different formats are also different, it is necessary to identify which content data annotations in the code according to the annotation identifiers in the code. In order to simply obtain the interface annotation information summarized by the code, this application also provides another method:
[0101] Please refer to Figure 2 , Figure 2 The flowchart of the preset code generation method provided in the embodiment of the present application, step S12 includes:
[0102] S121: Determine the comment start position and comment end position in the implementation code by using the algorithm format of the implementation code;
[0103] S122: obtaining interface annotation information based on data between the annotation start position and the annotation end position;
[0104] Step S13 includes:
[0105] S131: parsing the interface annotation information using a preset data structure to obtain API structure information, wherein the preset data structure is a preset annotation compilation structure;
[0106] S132: Generate a preset code based on the structure information of the API.
[0107] When determining the annotation compilation format, the data format can be identified based on the attribute parameters of the development web platform, or based on the characteristic statements in the back-end compiled code; then, based on the data format, the identifiers of the comment start and end positions are determined, and finally each comment start and each comment end position is found in the code. When obtaining comments, the first comment information is obtained from the first comment start position, and it is determined that the first comment information has been obtained after encountering the first comment end position, and the second comment information is obtained after the second comment start position, and so on until all the comments in the code are obtained.
[0108] In addition, a document generator suitable for developing a web platform may be determined, and a format recognizable by the document generator may be used as a comment compilation format.
[0109] For example, when the web development platform is a Java platform, javadoc can be used as a document generator for the web development platform. Javadoc can recognize comments that start with / ** and end with * / . Therefore, when backend developers compile comments, they also need to start with / ** and end with * / . When obtaining comments, when / ** is detected, subsequent data is obtained, and when * / is detected, it is determined that the comment information has been obtained.
[0110] In this way, we first determine the start and end positions of the comments in the code, obtain the complete comment information for back-end development, and then parse the comment information to obtain the preset comment compilation structure to ensure the uniformity of the compilation method. The entire code generation process is achieved through the precise identification of the comment data location and the standardization of code compilation. This not only improves the quality of the code, but also ensures the consistency between the front-end and back-end interfaces, effectively reducing the interface inconsistencies that may occur during the front-end and back-end development process and improving development efficiency.
[0111] In addition, when backend developers need to modify the API interface code, they need to send the code and comments to the development web platform in a timely manner to ensure that the front end is informed of the changes in the API interface in a timely manner. This not only requires backend developers to spend extra work to ensure the timeliness of the API compilation status, but also increases the development pressure of backend developers.
[0112] In order to reduce the maintenance cost of back-end developers, the back-end can issue a regular task to the development web platform in the earliest stage of the deployment environment.
[0113] The specific process is as follows:
[0114] Get the scheduled tasks sent by the backend development platform;
[0115] Determine the execution frequency and execution cycle duration of the scheduled task;
[0116] According to the execution frequency and the execution cycle duration, the step of obtaining the implementation code of the API compiled by the back-end development platform is periodically performed.
[0117] In this way, the development platform can periodically obtain the API implementation code compiled by the backend during the entire API compilation period, and periodically execute the solution of this application without the need for manual updates of the backend, thereby ensuring the timeliness of the API compilation status.
[0118] In an optional solution of the embodiment of the present invention, considering that in the prior art, when the front end develops the API interface, it needs to develop after the back end has completed debugging the API interface, resulting in the front end wasting time before the back end has completed debugging the API interface, thereby reducing the development efficiency of the entire network service. In order to improve the development efficiency of the network service, the present application also provides another method:
[0119] Please refer to Figure 3 , Figure 3 A flowchart of an interface testing method provided in an embodiment of the present application.
[0120] After step 15, the method further comprises:
[0121] S161: when a development request from a front-end development platform is obtained, back-end debugging data is obtained, wherein the back-end debugging data is data generated when the back-end development platform debugs an API;
[0122] S162: Generate corresponding simulation data mock according to the backend debugging data;
[0123] S163: Send the mock to the front-end development platform.
[0124] In order to improve the development efficiency of network services, the front-end and back-end need to be developed in parallel, that is, the front-end can develop the API interface before the back-end has completed debugging the API interface. To achieve this, when the back-end has not started debugging the API interface, you can first compile a set of predefined parameters as mock data based on the functions that the API interface needs to implement. The front-end developers develop the API interface based on the mock data. The predefined parameters refer to the data used to simulate the network service in actual applications.
[0125] For example, suppose the function that the API interface needs to implement is account login, and the mock data refers to the account and password. After the front-end developer enters the account and password on the front end, the front end will query the back end for the corresponding data, and then return the login result to the front end. Specifically, when the back end cannot find the data corresponding to the account, it returns the result that the account does not exist to the front end; when the back end cannot find the data corresponding to the password, it returns the result that the password is wrong to the front end; when the back end finds the data corresponding to the account and password, it returns the result of successful login to the front end. Since the mock data is known, when the front-end developer develops the API interface, he can know whether the front-end development process is correct based on the data returned to the front end.
[0126] When the backend has started debugging the API interface, it is necessary to obtain the debugging data of the API interface on a regular or real-time basis, and generate new mock data based on the debugging data. This is because as the debugging progress of the API interface increases, the functions of the API interface will become richer and more detailed. In order to allow the front end to continue development in time according to the changes in the API interface, it is necessary to obtain the debugging data of the backend to generate new mock data.
[0127] When obtaining backend debugging data, the main thing is to obtain the URL (Uniform Resource Locator) of the API interface, the request function used for debugging on the backend, and the parameters of the API interface response request function. The response parameters obtained include the parameters for correct response, the parameters for error response, and the parameters corresponding to the exception when a problem occurs. In addition, some plug-ins for automatic data collection can be added to the development web platform, such as Swagger UI or Postman, etc., and these plug-ins can be used to automatically collect requests and responses when debugging the API interface on the backend.
[0128] When generating mock data, you can directly use the response of the API interface as mock data, and use the request when debugging the API interface in the backend as the request structure of the mock data. Taking the above account login example as an example, as the backend debugs the API interface, the account login is subdivided into multiple account login methods. When the frontend enters the account and password, it is also necessary to select the account login method. The backend needs to query the data corresponding to the account and password according to the account login method, and finally return the login result to the frontend.
[0129] By generating mock data, the front-end can determine the actual function of the API interface before the back-end completes debugging of the API interface, so that the front-end can directly develop the API interface according to the mock data, without having to wait until the back-end completes debugging of the API interface before developing the front-end, thereby improving the development efficiency of network services.
[0130] Considering that there may be some neglected problems during the debugging or development of the API interface, after the network service is developed, the actual function may not be consistent with the expectation, and the entire network service needs to be repaired and rectified, which seriously affects the development efficiency of the network service. In order to timely discover errors and defects found during the development or debugging of the API interface, this application also provides another method:
[0131] Please refer to Figure 3 , Figure 3 A flowchart of an interface testing method provided in an embodiment of the present application.
[0132] After step S163, the method further includes:
[0133] S164: Acquire front-end development data, wherein the front-end development data is data generated when the front-end development platform develops an API;
[0134] S165: Generate API test cases based on backend debugging data and frontend development data;
[0135] S166: When the test instruction is received, the test case is called to test the API function and obtain the API test result.
[0136] Obtain backend debugging data and frontend development data to determine the expected responses of the API interface under different requests (correct responses, error responses, and abnormal responses mentioned in the above embodiments). Then design different test cases for different situations.
[0137] Specifically, the functions that the API interface needs to implement in the current development stage are determined based on the request and expected response; based on the functions, various parameters of the test case are generated. These parameters include the test name, test description, constraints, test steps, test data, and expected results of the test case. Among them, the test name represents the unique identifier of the test case, which can be generated randomly or according to a predefined numbering sequence; the test description represents the purpose of the test case, and the corresponding description needs to be set according to the predefined API interface functions; the constraints represent the prerequisites for executing the test case, such as whether a task has been completed; the test steps refer to the specific process of the test case; the test data refers to the data required by the test steps; the expected results are equal to the expected responses.
[0138] Let's continue with the account login example above: it is known that the function that the API interface needs to implement is account login. Based on this function, various parameters of the test case are generated, among which the test name table is "sigin001"; the test description is "verification of the account login function"; the constraint is "the input account must be a registered account"; the test steps refer to the specific process of account login (such as: first open the API interface, then enter the account password, and finally submit the request to the backend); the test data is the specific account and password; the expected result is the login result returned by the backend through the API interface, such as login success or failure.
[0139] When using test cases, by comparing the actual results with the expected results, you can determine whether there are problems in the back-end debugging API interface process.
[0140] In this way, as the front-end and back-end debug and develop the API interface, test cases are continuously generated based on the front-end development data and the back-end debugging data. When the tester sends a test instruction, these test instructions can be called to perform the test. Exceptions that occur during debugging and development can be discovered in a timely manner, and the front-end and back-end can be notified to repair the exceptions in a timely manner.
[0141] In addition, testers can also compile test cases based on their own understanding of the API interface functions and add the test cases to the development web platform. When the API interface and network services are actually put into use, the backend can also regularly reuse these test cases to monitor the operation of the API interface and maintain the API interface.
[0142] Considering that when implementing a function of an API interface, multiple tasks need to be executed in sequence to achieve it. When an API interface function is abnormal, any task may be an abnormal point, and the number of abnormal points may be multiple; in addition, there are dependencies between tasks. When one task is abnormal, other tasks may also be abnormal, which makes it difficult to troubleshoot API interface abnormalities and find the root cause of the abnormality. In order to reduce the difficulty of interface abnormality troubleshooting, this application also provides another method:
[0143] The method also includes:
[0144] When the test result is abnormal, determine the execution order of tasks in the test case;
[0145] Test the tasks in the test case in sequence according to the task execution order;
[0146] When a task exception is detected, the API function exception is determined and the task with the exception is displayed.
[0147] When an API interface anomaly is detected, a whole task chain that implements the API interface function is derived based on the dependencies between the tasks being executed. Then, each task in the chain is re-executed in order from first to last. If a task is found to take too long to execute, or the data format of the task output is incorrect, the task will be judged to be abnormal. If the task has not output results after a period of execution, the task will be skipped and judged to have an abnormality of too long execution time. When all tasks in the chain are executed, all tasks that are judged to have abnormalities will be displayed.
[0148] It should be noted that if a task is skipped and the next task is judged to be abnormal, the skipped task can be executed again and the execution time of the task can be extended. If the task still cannot output results after a longer period of time, it will be judged to be abnormal, and other subsequent tasks can be temporarily judged to be normal. Wait until the task is repaired before testing other subsequent tasks.
[0149] When deriving a task chain based on dependencies, it is necessary to determine it based on the read-write relationship of the tasks. When a task writes a certain data, it is found that another task will read the data. Based on this relationship, the order of the two tasks can be determined, and the task chain can be constructed based on the order. Take an example as an example. Assume that there are three tasks A, B, and C. Task A reads data 1 and writes data 2, task B reads data 2 and writes data 3, and task C reads data 3 and implements business functions. It can be seen that the task chain between these three tasks is data 1-task A-data 2-task B-data 3-task C.
[0150] In this way, when an abnormality occurs in the test result of the API interface, a task chain of the API interface is constructed, and each task is executed in sequence according to the order of each task. When an abnormality is detected in a task, it is displayed, and the interface abnormality can be automatically troubleshooted, reducing the difficulty of abnormality troubleshooting.
[0151] Please refer to Figure 6 , Figure 6 A schematic diagram of a network service development process provided by an embodiment of the present application. For the development of the entire network service, it can be used Figure 6 The process shown in the figure is described as follows: the backend compiles the comments so that the development web platform can generate the API interface based on the comments. The backend then configures a scheduled task for the development web platform so that the development web platform can regularly obtain the comments to synchronize the API interface. After the development web platform generates the API interface, it displays it to the frontend. After the frontend learns the API interface, it realizes the interface alignment between the frontend and the backend.
[0152] During the development process, the backend and frontend can be developed in parallel, and data from the development process can be obtained regularly. Based on these data, corresponding test cases are generated for testers to test. These test cases will be retained, and the backend can reuse these test cases to maintain the API interface during daily maintenance.
[0153] Also, please refer to Figure 7 , Figure 7 A schematic diagram of an interface development architecture provided in an embodiment of the present application, Figure 7 Describes the relationship between the front-end and the back-end. Among them, goaccess represents log analysis, which is used to facilitate developers to monitor the development process of the entire network business; GW represents the gateway between the front-end and the back-end, and all requests sent by the front-end to the back-end must pass through GW; Registry represents the addresses of various back-end functions and services, and its function is to determine the target of the front-end request; Atlas back-end is the actual function or service that processes the front-end request; MongoDB and Mysql are both databases that store the data required for various requests, respectively, and Mock Server is a service that generates Mock data; UML Server is a service that determines the interface document based on the interface annotation; postwoman is a service that automatically collects requests and corresponding services when debugging API interfaces; Draw.io is equivalent to the visual framework of the platform.
[0154] Please refer to Figure 8 , Figure 8 A schematic diagram of the structure of an interface processing device provided in this application includes:
[0155] At least one communication interface 112; at least one bus 114 connected to the at least one communication interface 112; at least one processor 111 connected to the at least one bus 114; at least one memory 113 connected to the at least one bus 114, wherein the processor 111 is configured to:
[0156] Obtaining the implementation code of the application programming interface API compiled by the back-end development platform, wherein the implementation code is the interface code of the API, which is used to generate the API of the target structure, and the status of the implementation code is that the compilation is not completed;
[0157] Determining interface annotation information in the implementation code;
[0158] Determine and generate a corresponding preset code according to the interface annotation information;
[0159] Calling the preset code to generate the API of the target structure;
[0160] Determine parameter information of the API, and send the parameter information to the front-end development platform.
[0161] For a detailed introduction to the interface processing device provided in the present application, please refer to the above-mentioned embodiment of the interface processing method, and the present application will not go into details here.
[0162] Please refer to Fig. 9 , Fig. 9 A schematic diagram of the structure of an interface processing system provided for this application includes:
[0163] A code acquisition unit 211 is used to acquire the implementation code of the application programming interface API compiled by the back-end development platform, wherein the implementation code is used to generate the API of the target structure and has not been compiled;
[0164] An annotation acquisition unit 212, used to determine the interface annotation information in the implementation code;
[0165] A code generating unit 213, used to generate a corresponding preset code according to the interface annotation information;
[0166] A code calling unit 214, used for calling the preset code to generate the API of the target structure;
[0167] The parameter sending unit 215 is used to determine the parameter information of the API and send the parameter information to the front-end development platform.
[0168] For a detailed introduction to the interface processing system provided in the present application, please refer to the above-mentioned embodiment of the interface processing method, and the present application will not go into details here.
[0169] Based on the above embodiments:
[0170] In some embodiments, the parameter sending unit 215 includes:
[0171] A query instruction determination unit, used to obtain a target operation received by the front-end development platform, and determine a query instruction corresponding to the target operation, wherein the target operation is used to query a target parameter in the parameter information;
[0172] The query unit is used to obtain the target parameter corresponding to the query instruction based on the parameter information received by the front-end development platform, and send the target parameter to the front-end development platform to display the target parameter.
[0173] In some embodiments, the annotation acquisition unit 212 includes:
[0174] A comment position determination unit, used to determine a comment start position and a comment end position in the implementation code by using an algorithm format of the implementation code;
[0175] An annotation information acquisition unit, used to obtain interface annotation information based on data located between the annotation start bit and the annotation end bit;
[0176] The code generation unit 213 includes:
[0177] An annotation parsing unit, used to parse the interface annotation information using a preset data structure to obtain the structure information of the API, wherein the preset data structure is a preset annotation compilation structure;
[0178] The structure generation unit is used to generate preset codes based on the structure information of the API.
[0179] In some embodiments, the system further comprises:
[0180] The task acquisition unit is used to obtain the scheduled tasks sent by the back-end development platform;
[0181] A cycle parameter determination unit, used to determine the execution frequency and execution cycle duration of the scheduled task;
[0182] A cyclic triggering unit is used to periodically execute the step of obtaining the implementation code of the API compiled by the back-end development platform according to the execution frequency and the execution cycle duration.
[0183] In some embodiments, the system further comprises:
[0184] A backend data acquisition unit, configured to acquire backend debugging data when a development request from the frontend development platform is acquired, wherein the backend debugging data is data generated when the backend development platform debugs the API;
[0185] The mock generation unit is used to generate corresponding simulation data mock according to the backend debugging data;
[0186] The mock sending unit is used to send the mock to the front-end development platform.
[0187] In some embodiments, the system further comprises:
[0188] A front-end data acquisition unit, used to acquire front-end development data after sending the mock to the front-end development platform, wherein the front-end development data is data generated when the front-end development platform develops an API;
[0189] The test case generation unit is used to generate API test cases based on backend debugging data and frontend development data;
[0190] The functional testing unit is used to call the test case to test the API function when receiving the test instruction, obtain the API test result, and display it.
[0191] In some embodiments, the system further comprises:
[0192] An execution order determination unit, used to determine the execution order of tasks in a test case when the test result is abnormal;
[0193] The task test unit is used to test the tasks in the test case in sequence according to the task execution order;
[0194] The anomaly detection unit is used to determine the functional anomaly of the API and display the task with the anomaly when an anomaly is detected in the task.
[0195] The present application also provides a computer storage medium storing computer executable instructions, wherein the computer executable instructions are used to execute any of the above-mentioned interface processing methods.
[0196] For a detailed introduction to the computer storage medium provided in this application, please refer to the above-mentioned embodiment of the interface processing method, and this application will not go into details here.
[0197] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, i.e., they may be located in one place, or may be distributed over multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0198] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the relevant technology can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods of each embodiment or some parts of the embodiment.
[0199] It should be understood that the terms used herein are for the purpose of describing specific example embodiments only and are not intended to be limiting. Unless the context clearly indicates otherwise, the singular forms "a", "an", and "" as used herein may also be meant to include plural forms. The terms "comprise", "include", "contain", and "have" are inclusive and therefore specify the presence of stated features, steps, operations, elements, and / or parts, but do not exclude the presence or addition of one or more other features, steps, operations, elements, parts, and / or combinations thereof. The method steps, processes, and operations described herein are not to be construed as necessarily requiring them to be performed in the specific order described or illustrated, unless the order of execution is clearly indicated. It should also be understood that additional or alternative steps may be used.
[0200] The above is only a specific embodiment of the present invention, so that those skilled in the art can understand or implement the present invention. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but should conform to the widest scope consistent with the principles and novel features applied herein.< / interface:id> < / interface:id> < / interface:id> < / interface:id>
Claims
1. An interface processing method, characterized in that: include: Obtaining the implementation code of the application programming interface API compiled by the back-end development platform, wherein the implementation code is the interface code of the API, which is used to generate the API of the target structure, and the status of the implementation code is that the compilation is not completed; Determining interface annotation information in the implementation code; Determine and generate a corresponding preset code according to the interface annotation information; Calling the preset code to generate the API of the target structure; Determine parameter information of the API, and send the parameter information to the front-end development platform.
2. The method according to claim 1, characterized in that After sending the parameter information to the front-end development platform, the method further includes: Acquire the target operation received by the front-end development platform, and determine the query instruction corresponding to the target operation, wherein the target operation is used to query the target parameter in the parameter information; Based on the parameter information received by the front-end development platform, a target parameter corresponding to the query instruction is obtained, and the target parameter is sent to the front-end development platform to display the target parameter.
3. The method according to claim 1, characterized in that: Determining interface annotation information in the implementation code, and generating corresponding preset code according to the interface annotation information, including: Determine the comment start position and comment end position in the implementation code by using the algorithm format of the implementation code; Based on the data between the comment start bit and the comment end bit, the interface comment information is obtained; Parsing the interface annotation information using a preset data structure to obtain the structure information of the API, wherein the preset data structure is a preset annotation compilation structure; The preset code is generated based on the structural information of the API.
4. The method according to claim 1, characterized in that: The method further comprises: Obtaining the scheduled tasks sent by the backend development platform; Determine the execution frequency and execution cycle duration of the scheduled task; According to the execution frequency and the execution cycle duration, the step of obtaining the implementation code of the API compiled by the back-end development platform is periodically performed.
5. The method according to any one of claims 1 to 4, characterized in that: After sending the parameter information to the front-end development platform, the method further includes: When the development request of the front-end development platform is obtained, back-end debugging data is obtained, wherein the back-end debugging data is data generated when the back-end development platform debugs the API; Generate corresponding simulation data mock according to the backend debugging data; The mock is sent to the front-end development platform.
6. The method according to claim 5, characterized in that After sending the mock to the front-end development platform, the method further includes: Acquire front-end development data, wherein the front-end development data is data generated when the front-end development platform develops the API; Generate a test case for the API based on the backend debugging data and the frontend development data; When a test instruction is received, the test case is called to test the function of the API to obtain the test result of the API.
7. The method according to claim 6, characterized in that The method further comprises: When the test result is abnormal, determining the execution order of tasks in the test case; Testing the tasks in the test case in sequence according to the task execution order; When it is detected that the task is abnormal, the function of the API is abnormal, and the task with the abnormality is displayed.
8. An interface processing device, characterized in that: include: at least one communication interface; at least one bus connected to the at least one communication interface; at least one processor connected to the at least one bus; at least one memory connected to the at least one bus, wherein the processor is configured to: Obtaining the implementation code of the application programming interface API compiled by the back-end development platform, wherein the implementation code is the interface code of the API, which is used to generate the API of the target structure, and the status of the implementation code is that the compilation is not completed; Determining interface annotation information in the implementation code; Determine and generate a corresponding preset code according to the interface annotation information; Calling the preset code to generate the API of the target structure; Determine parameter information of the API, and send the parameter information to the front-end development platform.
9. An interface processing system, characterized in that: include: A code acquisition unit, used to acquire the implementation code of the application programming interface API compiled by the back-end development platform, wherein the implementation code is used to generate the API of the target structure and has not been compiled; An annotation acquisition unit, used to determine the interface annotation information in the implementation code; A code generating unit, used to generate a corresponding preset code according to the interface annotation information; A code calling unit, used for calling the preset code to generate the API of the target structure; The parameter sending unit is used to determine the parameter information of the API and send the parameter information to the front-end development platform.
10. A computer storage medium, characterized in that: Computer executable instructions are stored, and the computer executable instructions are used to execute the interface processing method described in any one of claims 1 to 7 of the present application.
