Method and front-end device for processing mock data of the front-end device
By storing Mock data in the persistent storage medium of the front-end device, the problem of work stagnation caused by the back-end progress falling behind in front-end development is solved, realizing the persistence and flexible operation of Mock data, and improving development efficiency.
Patent Information
- Application Number
- CN202211313181.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-10-25
- Publication Date
- 2026-02-27
- Estimated Expiration
- 2042-10-25
AI Technical Summary
In front-end development, the back-end's lagging progress prevents the front-end from obtaining interface data, affecting the work progress. Furthermore, setting up a Mock test server is costly and lacks flexibility, resulting in low development efficiency.
Mock data is stored in the persistent storage medium of the front-end device to achieve persistence of the Mock data, support various request operations, including reading, writing, modifying and deleting, and ensure that the data is still accessible after the browser page is refreshed or restarted.
It reduces development costs, improves the flexibility and efficiency of front-end development, and allows users to easily debug the development interface and view the effects of request operations.
Smart Images

Figure CN115878699B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the field of information technology and computer technology, and particularly relates to a method for processing Mock data of a front-end device and the front-end device. BACKGROUND
[0002] At present, the development of a project in the computer industry is often carried out simultaneously by front-end and back-end, but the front-end development work depends on the interface data provided by the back-end, therefore, when the front-end and back-end work progress is inconsistent, for example, the back-end work progress lags behind and cannot provide interface data for the front-end, the work progress of the front-end is often affected.
[0003] To solve this problem, the related technology provides a solution including: building a Mock test server, and the front-end carries out test development by using the simulated fake data. However, the cost of building the Mock test server is high, the use experience is not friendly, and the flexibility is poor, which leads to the reduction of the front-end development efficiency. SUMMARY
[0004] The present application provides a method for processing Mock data of a front-end device and the front-end device, which can persist data without any support of a back-end application, flexibly simulate various request operations, and improve the front-end development efficiency.
[0005] In a first aspect, the present application provides a method for processing Mock data of a front-end device, the front-end device comprising a processor, a display and a persistent storage medium, and the display displays a browser page, the method is applied to the processor, and the method comprises the following steps: receiving a read request operation for a target Mock interface of the browser page; in response to the read request operation, searching for target Mock data corresponding to the target Mock interface from the persistent storage medium, and returning the target Mock data to the target Mock interface.
[0006] It can be understood that the Mock data is stored in the persistent storage medium of the front-end device in the embodiments of the present application, so as to realize the persistence of the Mock data, and therefore, in the process of responding to the request operation, if the Mock data corresponding to the target Mock interface is persistent data, the target Mock data is searched from the persistent storage medium in response to the read request operation for the target Mock interface.
[0007] The target Mock data can be Mock data stored in the persistent storage medium in the initialization process. Alternatively, the target Mock data can be newly added Mock data of a user. Alternatively, the target Mock data can be Mock data after modification of Mock data corresponding to the target Mock interface, and the like. It can be understood that the target Mock data is not limited in the present application. Regardless of any operation on the Mock data corresponding to the target Mock interface, the Mock data after the operation can be stored in the persistent storage medium. In this way, when a read request operation for the target Mock interface is received subsequently, the target Mock data can be found from the persistent storage medium.
[0008] In summary, by storing the Mock data in the persistent storage medium of the front-end device, the present application can realize the persistence of the Mock data without any support of the back-end application, so that the Mock data can cover more scenarios that cannot be covered in related technologies. In this way, on the one hand, the development cost is reduced; on the other hand, the user can more flexibly, conveniently and comprehensively debug the front-end development interface, thereby improving the front-end development efficiency.
[0009] In a possible implementation, the target Mock data corresponding to the target Mock interface is found from the persistent storage medium in response to the read request operation, including: in a case where the Mock data corresponding to the target Mock interface is persistent data, the target Mock data corresponding to the target Mock interface is found from the persistent storage medium in response to the read request operation.
[0010] It can be understood that the present application can determine the processing mode of the read request operation for the target Mock interface by determining whether the Mock data corresponding to the target Mock interface is persistent data. In a case where the Mock data corresponding to the target Mock interface is persistent data, the target Mock data is found from the persistent storage medium in response to the read request operation for the target Mock interface. In a case where the Mock data corresponding to the target Mock interface is not persistent data, other processing modes are adopted, for example, Mock data is randomly generated according to a data type agreed in an interface document of the target Mock interface, and the like.
[0011] In another possible implementation, the read request operation includes an interface identifier of the target Mock interface, and the method further includes: in a case where the interface identifier of the target Mock interface includes a persistent identifier, it is determined that the Mock data corresponding to the target Mock interface is persistent data; wherein the persistent identifier is used to indicate that data persistence is required.
[0012] It can be understood that when the Mock interface is generated according to the interface document, whether the Mock data corresponding to the interface is persistent data is determined according to the business information (or the role of the interface) of the interface corresponding to the interface defined in the interface document; if yes, the persistent identifier is added in the interface identifier of the Mock interface when the Mock interface is generated according to the interface document. In this way, the processor can determine whether the Mock data corresponding to the Mock interface is persistent data according to whether the persistent identifier is included in the interface identifier of the Mock interface.
[0013] In another possible implementation, the method further includes: in the case that the read request operation is not successfully responded, returning an exception reason of the read request operation to the target Mock interface; the exception reason is used to indicate the reason why the read request operation is not successfully responded.
[0014] It can be understood that in the case that the read request operation is successfully responded, the target Mock data is returned to the target Mock interface; in the case that the read request operation is not successfully responded, an exception reason of the read request operation is returned to the target Mock interface, so that the user knows that the read request operation is not successfully responded and can solve the problem according to the exception reason.
[0015] In another possible implementation, the persistent storage medium includes: a first data table and a second data table; the first data table is used to store Mock data corresponding to an interface satisfying the RESTful standard; the second data table is used to store Mock data corresponding to an interface not satisfying the RESTful standard; the above-mentioned finding, from the persistent storage medium, the target Mock data corresponding to the target Mock interface in response to the read request operation includes: if the target Mock interface satisfies the RESTful standard, finding the target Mock data corresponding to the target Mock interface from the first data table; if the target Mock interface does not satisfy the RESTful standard, finding the target Mock data corresponding to the target Mock interface from the second data table.
[0016] It can be understood that the Mock data added by the application is stored in the corresponding data table according to whether the target Mock interface satisfies the RESTful standard, which is convenient for storage and management and convenient for finding.
[0017] In another possible implementation, before receiving the read request operation of the target Mock interface of the browser page, the method further includes: receiving a modification request operation of the target Mock interface; in response to the modification request operation, finding the target Mock data from the persistent storage medium and modifying the target Mock data; storing and returning the modified target Mock data to the target Mock interface.
[0018] It can be understood that the application can modify the target Mock data in the persistent storage medium and store the modified target Mock data in the persistent storage medium. In this way, compared with the related art method that cannot view the effect of modifying data, the application embodiment can store the modified target Mock data in the persistent storage medium of the front-end device. In this way, when a request operation for the target Mock interface is received subsequently, the modified target Mock data can be found from the persistent storage medium.
[0019] In another possible implementation, before receiving the read request operation for the target Mock interface of the browser page, the method further includes: receiving a write request operation for the target Mock interface; and in response to the write request operation, storing the target Mock data in the persistent storage medium.
[0020] It can be understood that, compared with the related art method that cannot view the effect of adding data, the application can store the added target Mock data in the persistent storage medium of the front-end device to realize the persistence of the target Mock data. In this way, when a request operation for the target Mock interface is received subsequently, the added target Mock data can be found from the persistent storage medium.
[0021] In another possible implementation, the receiving of the read request operation for the target Mock interface of the browser page includes: after restarting the front-end device, receiving the read request operation for the target Mock interface of the browser page.
[0022] It can be understood that, compared with the related art method that cannot view the effect of adding, deleting or modifying data after the front-end device is restarted, the application can store the target Mock data after the adding, modifying or deleting operation in the persistent storage medium of the front-end device to realize the persistence of the target Mock data. In this way, after the front-end device is restarted, when a request operation for the target Mock interface is received, the added target Mock data can be found from the persistent storage medium.
[0023] In another possible implementation, before receiving the read request operation for the target Mock interface of the browser page, the method further includes: traversing the Mock interfaces of the browser page to select candidate Mock interfaces from the Mock interfaces; wherein the Mock data corresponding to the candidate Mock interfaces is persistent data; and storing the Mock data corresponding to the candidate Mock interfaces in the persistent storage medium.
[0024] It can be understood that the precondition for obtaining the Mock data from the persistent storage medium is that the Mock data exists in the persistent storage medium, therefore, the application first stores the Mock data to be obtained from the persistent storage medium in the persistent storage medium before responding to the request operation, so that the Mock data can be obtained from the persistent storage medium when the request operation of obtaining the Mock data is received subsequently.
[0025] In another possible implementation, the persistent storage medium includes: a first data table and a second data table; the first data table is used to store Mock data corresponding to an interface meeting the RESTful standard; the second data table is used to store Mock data corresponding to an interface not meeting the RESTful standard; and the storing of the Mock data corresponding to the candidate Mock interface in the persistent storage medium includes: storing the Mock data corresponding to the candidate Mock interface in the first data table in the case that the candidate Mock interface meets the RESTful standard; and storing the Mock data corresponding to the candidate Mock interface in the second data table in the case that the candidate Mock interface does not meet the RESTful standard.
[0026] It can be understood that the application stores the Mock data corresponding to the candidate Mock interface in different data tables according to whether the candidate Mock interface meets the RESTful standard, wherein the primary keys of the different data tables are different. In this way, the Mock data corresponding to the Mock interface is stored separately according to the characteristics of the Mock interface, which facilitates storage and management, and facilitates searching.
[0027] In another possible implementation, the persistent storage medium is a data cache device built in a browser.
[0028] It can be understood that the persistent storage medium provided by the application is a data cache device built in a browser of a front-end device, and does not involve any back-end application and server, thereby reducing the cost of front-end development.
[0029] In a second aspect, the application provides a processor applied to a front-end device; the front-end device further includes a display and a persistent storage medium, and a browser page is displayed on the display; the processor includes: a receiving module configured to receive a read request operation for a target Mock interface of the browser page; and a searching module configured to search, in response to the read request operation, target Mock data corresponding to the target Mock interface from the persistent storage medium, and return the target Mock data to the target Mock interface.
[0030] In a possible implementation, the finding module is specifically configured to, in response to the read request operation, find the target Mock data corresponding to the target Mock interface from the persistent storage medium, in a case where the Mock data corresponding to the target Mock interface is persistent data.
[0031] In another possible implementation, the read request operation includes an interface identifier of the target Mock interface, and the processor further includes a determining module configured to determine that the Mock data corresponding to the target Mock interface is persistent data, in a case where the interface identifier of the target Mock interface includes a persistent identifier, where the persistent identifier is used to indicate that data persistence is required.
[0032] In another possible implementation, the processor further includes a returning module configured to return an exception reason of the read request operation to the target Mock interface, in a case where the read request operation is not successfully responded.
[0033] In another possible implementation, the persistent storage medium includes a first data table and a second data table, the first data table is used to store Mock data corresponding to an interface that meets a RESTful standard, and the second data table is used to store Mock data corresponding to an interface that does not meet the RESTful standard, and the finding module is specifically configured to find the target Mock data corresponding to the target Mock interface from the first data table, in a case where the target Mock interface meets the RESTful standard, and find the target Mock data corresponding to the target Mock interface from the second data table, in a case where the target Mock interface does not meet the RESTful standard.
[0034] In another possible implementation, the receiving module is further configured to receive a modification request operation for the target Mock interface, the finding module is further configured to find the target Mock data from the persistent storage medium and modify the target Mock data in response to the modification request operation, and the storage module is configured to store the modified target Mock data and return the modified target Mock data to the target Mock interface.
[0035] In another possible implementation, the receiving module is further configured to receive a write request operation for the target Mock interface, and the finding module is further configured to store the target Mock data in the persistent storage medium in response to the write request operation.
[0036] In another possible implementation, the receiving module is specifically configured to receive the read request operation for the target Mock interface of the browser page after the front-end device is restarted.
[0037] In another possible implementation, the processor further includes an initialization module, configured to traverse Mock interfaces of the browser page, and select a candidate Mock interface from the Mock interfaces; the Mock data corresponding to the candidate Mock interface is persistent data; and the Mock data corresponding to the candidate Mock interface is stored in the persistent storage medium.
[0038] In another possible implementation, the persistent storage medium includes a first data table and a second data table; the first data table is configured to store Mock data corresponding to an interface satisfying a RESTful standard; the second data table is configured to store Mock data corresponding to an interface not satisfying the RESTful standard; and the initialization module is specifically configured to, in a case where the candidate Mock interface satisfies the RESTful standard, store the Mock data corresponding to the candidate Mock interface in the first data table; and in a case where the candidate Mock interface does not satisfy the RESTful standard, store the Mock data corresponding to the candidate Mock interface in the second data table.
[0039] In another possible implementation, the persistent storage medium is a data cache device built in the browser.
[0040] In a third aspect, the present application provides a processor, including an interface and a control circuit; the interface is configured to interact with an external device; and the control circuit is configured to control the processor to execute the method for processing Mock data of a front-end device provided in the first aspect.
[0041] In a fourth aspect, the present application provides a front-end device, including a processor, a display, and a persistent storage medium; the display displays a browser page; the persistent storage medium is configured to store data; and the processor is configured to execute the method for processing Mock data of a front-end device provided in the first aspect.
[0042] In a fifth aspect, the present application provides a computer readable storage medium, which stores computer execution instructions; when the computer execution instructions run on a computer, the computer is caused to execute the method for processing Mock data of a front-end device provided in the first aspect.
[0043] In a sixth aspect, the present application provides a computer program product, which includes computer instructions; when the computer instructions run on a computer, the computer is caused to execute the method for processing Mock data of a front-end device provided in the first aspect.
[0044] The detailed description of the second aspect to the sixth aspect and various implementation manners thereof in the present application can refer to the detailed description in the first aspect and various implementation manners thereof; and the beneficial effects of the second aspect to the sixth aspect and various implementation manners thereof can refer to the beneficial effect analysis in the first aspect and various implementation manners thereof, which will not be repeated here.
[0045] These aspects or other aspects of the present application will be more apparent in the following description. BRIEF DESCRIPTION OF DRAWINGS
[0046] Figure 1 A hardware running environment schematic diagram involved in a method for processing Mock data of a front-end device provided by an embodiment of the present application;
[0047] Figure 2 A flow of a method for processing Mock data of a front-end device provided by an embodiment of the present application Figure One ;
[0048] Figure 3 A flow of a method for processing Mock data of a front-end device provided by an embodiment of the present application Figure Two ;
[0049] Figure 4 A flow of a method for processing Mock data of a front-end device provided by an embodiment of the present application Figure Three ;
[0050] Figure 5 A flow of a method for processing Mock data of a front-end device provided by an embodiment of the present application Figure Four ;
[0051] Figure 6 A flow of a method for processing Mock data of a front-end device provided by an embodiment of the present application Figure Five ;
[0052] Figure 7 A flow of a method for processing Mock data of a front-end device provided by an embodiment of the present application Figure Six ;
[0053] Figure 8 A flow of a method for processing Mock data of a front-end device provided by an embodiment of the present application Figure Seven ;
[0054] Figure 9 A flow of a method for processing Mock data of a front-end device provided by an embodiment of the present application Figure Eight ;
[0055] Figure 10 A schematic diagram of a browser page provided by an embodiment of the present applicationFigure One ;
[0056] Figure 11 A schematic of a browser page provided for an embodiment of the application Figure Two ;
[0057] Figure 12 A schematic of a browser page provided for an embodiment of the application Figure Three ;
[0058] Figure 13 A schematic of a browser page provided for an embodiment of the application Figure Four ;
[0059] Figure 14 A schematic of a browser page provided for an embodiment of the application Figure Five ;
[0060] Figure 15 A schematic of a processor provided for an embodiment of the application. DETAILED DESCRIPTION
[0061] The term “and / or” in the present application is merely used to associate associated objects, and means that three relationships can exist, for example, A and / or B can mean that three cases of A alone, A and B together, and B alone exist.
[0062] The terms “first” and “second” and the like in the description of the present application and the drawings are used to distinguish different objects, or to distinguish different treatments of the same object, and are not used to describe a specific order of the objects.
[0063] In addition, the terms “include” and “have” and any variations thereof mentioned in the description of the present application are intended to cover non-exclusive inclusion. For example, a process, method, system, product or device that includes a series of steps or units is not limited to the listed steps or units, but can optionally include other steps or units not listed, or can optionally include other steps or units inherent to the process, method, product or device.
[0064] It should be noted that in the embodiments of the present application, the words “exemplary” or “for example” are used to mean serving as an example, instance, or illustration. Any embodiment or design scheme described as “exemplary” or “for example” in the embodiments of the present application should not be construed as being more preferred or advantageous than other embodiments or design schemes. Rather, the use of “exemplary” or “for example” is intended to present relevant concepts in a specific manner.
[0065] In the description of the present application, unless otherwise specified, “a plurality of” means two or more.
[0066] In order to facilitate understanding of the technical solutions of the present application, the terms involved in the present application will be briefly introduced first.
[0067] 1、Mock technology refers to a technology of replacing some objects that are not easy to construct or obtain with simulated objects in the process of front-end development and testing, so as to facilitate development and testing. The simulated objects are referred to as Mock objects; optionally, the simulated objects can be simulated data (for example, Mock data); or the simulated objects can be simulated interfaces (for example, Mock interfaces).
[0068] 2、Hypertext Transfer Protocol (HTTP) defines the specification of text transmission between a client and a server. HTTP protocol defines a plurality of HTTP request operations, as shown in Table 1.
[0069] Table 1
[0070]
[0071] 3、Hypertext Transfer Protocol Secure (HTTPS) is a secure version of HTTP, which provides identity authentication and encrypted communication methods, and is widely used for secure communication on the World Wide Web, such as transaction payment. HTTPS request operations are the same as HTTP request operations, the difference is that HTTPS request operations increase the encryption and decryption process in the transmission process.
[0072] 4、Representation State Transfer (REST) is a design style and development method for network applications, which can reduce the complexity of development.
[0073] 5、Data persistence refers to the conversion of a data model in memory into a storage model, and the conversion of a storage model into a data model in memory, and the data model can be any data structure or object model, and the storage model can be a relational model, extensible markup language (XML), binary stream, etc.
[0074] 6、Front-end device refers to a device for interacting with a user. The front-end device does not include a back-end server.
[0075] 7、Browser page refers to a network page implemented based on a browser kernel, for example, the browser page can include a website page, a client page implemented based on a browser kernel, etc.
[0076] 8, the request operation mentioned in the embodiment of the application refers to the request operation of the Mock interface of the browser page, for example: read request operation, write request operation, modification request operation or delete request operation, etc. Optionally, the request operation provided by the embodiment of the application can be HTTP request operation or HTTPS request operation, etc. No limitation is made to this.
[0077] The above is the introduction of some concepts involved in the embodiment of the application, which will not be repeated below.
[0078] In the related art, a Mock test server is built to receive the request operation sent by the browser page of the front-end device, and return the preset Mock data in response to the request operation. However, the related art has the following problems: 1, the cost of building the Mock test server is high; 2, the Mock test server can only return the preset Mock data, and the flexibility is poor; 3, the effect of the request operation cannot be viewed, for example, if the request operation requests to delete the information of user A, in response to the request operation, after the preset Mock data is returned, the data on the browser page is restored to the initial state with the refresh or restart of the browser page, and therefore, when the user views the user information next time, the browser page will still display the information of user A, so that the user cannot judge whether the request operation has effect, the test effect is poor, and the front-end development efficiency is reduced.
[0079] The application provides a method for processing Mock data of a front-end device, the idea of which is to store the Mock data in the persistent storage medium of the front-end device, so as to realize the persistence of the Mock data, and therefore, in the process of responding to the request operation, if the Mock data corresponding to the target Mock interface is persistent data, the target Mock data is searched from the persistent storage medium in response to the read request operation for the target Mock interface.
[0080] The target Mock data can be the Mock data stored in the persistent storage medium in the initialization process, or the target Mock data can be the Mock data newly added by the user, or the target Mock data can be the Mock data after the modification of the Mock data corresponding to the target Mock interface, etc. It can be understood that the application does not limit the target Mock data, and no matter what operation is performed on the Mock data corresponding to the target Mock interface, the Mock data after the operation can be stored in the persistent storage medium, so that the target Mock data can be searched from the persistent storage medium when the read request operation for the target Mock interface is received subsequently.
[0081] In summary, compared with the scheme of assisting front-end development by building a Mock test server, the embodiment of the application can at least produce the following beneficial effects: 1. Without any backend application support, the development cost is reduced; 2. By storing Mock data in the persistent storage medium of the front-end device, the persistence of Mock data is realized, so that the user can still obtain Mock data from the persistent storage medium with the refresh or restart of the browser page, so that the user can view the effect of the request operation; 3. Not only can the preset Mock data be returned, but also the Mock data can be operated (such as adding, deleting, modifying, etc.) in the persistent storage medium in response to the request operation, so that the user can more flexibly, conveniently and comprehensively debug the front-end development interface, and the front-end development efficiency is improved.
[0082] The embodiments provided by the application will be specifically introduced below in conjunction with the drawings of the specification.
[0083] Referring to Figure 1 , a hardware structure diagram of a hardware running environment related to the embodiments of the application is shown. As Figure 1 indicated, the method provided by the embodiments of the application is applied to a front-end device, which can be a PC, a smart phone, a tablet computer, an e-book reader, a portable computer and the like terminal device with an access function to the Internet.
[0084] As Figure 1 indicated, the front-end device 100 includes a processor 110, a display 120 and a persistent storage medium 130.
[0085] The processor 110 is the operation and control core of the front-end device 110, mainly used for interpreting computer instructions and processing data in computer software, and is the final execution unit of information processing and program running.
[0086] For example, the processor 110 can be various exemplary logic blocks, modules and circuits described in combination with the disclosure of the application. The processor 110 can also be a central processing unit, a general-purpose processor, a digital signal processor, an application-specific integrated circuit, a field programmable gate array or other programmable logic devices, transistor logic devices, hardware components or any combination thereof. The processor 110 can also be a combination of computing functions, such as one or more microprocessor combinations, combinations of DSP and microprocessor, etc.
[0087] In some embodiments, the processor 110 includes an interface and a control circuit; the interface is used to interact with external devices; the control circuit is used to control the processor to perform any method of processing the Mock data of the front-end device provided by the embodiments of the application.
[0088] The display 120 is configured to display a browser page.
[0089] The display 120 can be a liquid crystal display, an organic light-emitting diode (OLED) display, or the like. The embodiments of the present application do not limit the specific type, size, and resolution of the display 120.
[0090] The persistent storage medium 130 is configured to store data. In some embodiments of the present application, the persistent storage medium 130 is configured to store Mock data.
[0091] The persistent storage medium 130 can be a mechanical hard disk or a solid state disk, or the like.
[0092] Optionally, the persistent storage medium 130 can be configured to store a database built in the browser, such as an Indexed Database (IndexedDB) or a lightweight database (SQLite), or the like. The IndexedDB is a transactional database system that stores data in the form of key-value pairs, and data can be obtained or stored using a primary key key as an index. Each data record has a corresponding primary key, and the primary key is unique. SQLite is a lightweight embedded database. SQLite does not need to be configured, installed, and managed. SQLite provides application program interface (API) interfaces for C, Java, PHP, Python, and other languages. An application program can call the corresponding interface to perform data access operations.
[0093] In some embodiments, the front-end device 100 can further include a communication interface (not shown in the figure) configured to connect with other devices through a communication network. The communication network can be an Ethernet, a wireless access network, a wireless local area network (WLAN), or the like. Figure 1
[0094] In some other embodiments, the front-end device 100 can further include a bus (not shown in the figure) that can be an extended industry standard architecture (EISA) bus, or the like. The bus can be divided into an address bus, a data bus, a control bus, or the like. Figure 1
[0095] Those skilled in the art can understand that, Figure 1 The structure shown in the figure does not constitute a limitation on the front-end device, and in other embodiments, the front-end device can include more or fewer components than the figure, or combine certain components, or different component arrangements.
[0096] The method for processing Mock data of a front-end device provided in the present application will be described in detail below with reference to the accompanying drawings.
[0097] The method for processing Mock data of a front-end device provided in the embodiments of the present application can be used in the scenarios of front-end development or testing, for example, to assist the front-end device in software development, website development, applet development, etc. Optionally, the method for processing Mock data of a front-end device provided in the embodiments of the present application can also be applied to scenarios of processing other data of a front-end device, for example, to record data files generated in the process of software running, to realize the persistence of data files.
[0098] The method for processing Mock data of a front-end device provided in the embodiments of the present application can be executed by a processor in the front-end device. Optionally, the method provided in the embodiments of the present application can include an initialization process and a process of responding to a request operation. The initialization process refers to initializing a persistent storage medium to import Mock data in the persistent storage medium; the process of responding to a request operation refers to a process of reading or operating Mock data in the persistent storage medium in response to a received request operation.
[0099] In some embodiments, the initialization process is before the process of responding to a request operation. The specific content of the initialization process and the process of responding to a request operation can be referred to the following embodiments.
[0100] I. Initialization process
[0101] In some embodiments, as shown in Figure 2 the initialization process can be implemented as the following steps:
[0102] S201, check whether a target data table exists in the persistent storage medium. The target data table is used to store Mock data.
[0103] In some embodiments, the persistent storage medium provides an access interface to the outside, and the processor can access the persistent storage medium through the access interface and find whether the target data table exists in the persistent storage medium according to the name of the target data table.
[0104] If the target data table does not exist in the persistent storage medium, the following step S202 is executed;
[0105] If the target data table exists in the persistent storage medium, the following step S203 is executed.
[0106] In some embodiments, the target data table comprises: a first data table and a second data table; wherein the first data table is configured to store Mock data corresponding to a Mock interface satisfying a RESTful standard; and the second data table is configured to store Mock data corresponding to a Mock interface not satisfying the RESTful standard.
[0107] The Mock data corresponding to the Mock interface refers to Mock data that needs to be obtained through the Mock interface. For example, assuming that the request operation for the Mock interface is a GET request operation, and the GET request operation is configured to obtain user information through the Mock interface, the Mock data corresponding to the Mock interface includes the user information.
[0108] The Mock interface is a virtual interface generated according to a pre-agreed interface document. It can be understood that in the process of front-end and back-end separation development, the interface needs to be defined by front-end and back-end engineers, the interface document needs to be written, and then the development is performed according to the interface document. For example, the interface document includes but is not limited to the following contents: interface name (simple description of the interface), such as login interface, get interface, etc.; calling address of the interface (address of the resource called by the interface), such as uniform resource locator (URL) or custom identity (Identity, ID), etc.; calling mode, such as GET, PUT, POST or DELETE, etc.
[0109] The Mock interface satisfying the RESTful standard refers to an interface that needs to be called according to the calling mode specified by the RESTful standard. In the calling mode specified by the RESTful standard, the uniform resource locator (URL) is used to locate the resource, and does not include a verb (such as GET, POST, etc.) representing the operation mode, and the request method (Method) is used to represent the operation mode, and the Method includes: GET, DELETE, POST and PUT, etc. For example, the request operation issued according to the calling mode specified by the RESTful standard is: Method URL; wherein the URL represents the identifier of the resource requested by the request operation; and the Method represents the operation mode requested by the request operation. For example, the GET request operation issued according to the calling mode specified by the RESTful standard is: GET URL (for example, the request for viewing all tasks: GET http: / / xxx.x.x.x / xx); and the DELETE request operation issued according to the calling mode specified by the RESTful standard is: DELETE URL (for example, the request for deleting a task: DELETE http: / / xxx.x.x.x / xx).
[0110] The Mock interface that does not meet the RESTful standard refers to an interface that does not need to be called in the calling manner specified by the RESTful standard. For example, the Mock interface that does not meet the RESTful standard can be called in a user-defined calling manner. In the user-defined calling manner, the identification of the resource requested by the request operation can be a user-defined ID, and the operation manner requested by the request operation can be a user-defined operation manner, but the operation manner needs to be described so that the processor knows how to operate. For example, the operation of requesting to query a user can be described as: getUser; the operation of requesting to add a user can be described as: addUser; the operation of requesting to update a user can be described as: updateUser; and the operation of requesting to delete a user can be described as: deleteUser.
[0111] It can be understood that the target data table provided by the embodiments of the present application can include a first data table and a second data table, which are respectively used to store Mock data corresponding to interfaces meeting the RESTful standard and Mock data corresponding to interfaces not meeting the RESTful standard. In this way, according to the characteristics of the Mock interface, the Mock data corresponding to the Mock interface is stored respectively, which is convenient for storage and management, and facilitates searching.
[0112] In other embodiments, the target data table includes a third data table; wherein the third data table is used to store Mock data corresponding to Mock interfaces meeting the RESTful standard and Mock data corresponding to Mock interfaces not meeting the RESTful standard.
[0113] It can be understood that the target data table provided by the embodiments of the present application can be a third data table, and Mock data corresponding to Mock interfaces can be stored in the third data table regardless of whether the Mock interface meets the RESTful standard. In this way, in the process of responding to the request operation, it is not necessary to judge whether the RESTful standard is met, and the response process can be simplified.
[0114] S202, creating a target data table in a persistent storage medium.
[0115] In some embodiments, when the target data table includes a first data table and a second data table, the first data table and the second data table are created in the persistent storage medium.
[0116] For example, the first data table stores data in the form of key-value pairs (Key-Value), wherein the primary key Key is a URL. For example, the first data table can be represented in the form shown in Table 2 below:
[0117] Table 2
[0118]
[0119] In another example, the second data table stores data in the form of a key-value pair, where the primary key Key is a custom ID. In an example, the second data table can be represented in the form shown in Table 3 below:
[0120] Table 3
[0121]
[0122] In some embodiments, in the case where the target data table includes a third data table, the third data table is created in the persistent storage medium.
[0123] In an example, the third data table stores data in the form of a key-value pair, where the primary key of the third data table includes a URL and a custom ID. In an example, the third data table can be represented in the form shown in Table 4 below:
[0124] Table 4
[0125]
[0126] S203, traverse the Mock interfaces of the browser page and select a candidate Mock interface from the Mock interfaces. The Mock data corresponding to the candidate Mock interface is persistent data.
[0127] In S203, the browser page can be any browser page of the front-end device.
[0128] The Mock interface of the browser page refers to a Mock interface that needs to be called when a service provided by the browser page is used. In an example, assume that the services provided by the browser page include adding information, querying information, and modifying information; where the Mock interface that needs to be called when the service of adding information is used is a first Mock interface, the Mock interface that needs to be called when the service of querying information is used is a second Mock interface, and the Mock interface that needs to be called when the service of modifying information is used is a third Mock interface, then the Mock interface of the above browser page includes the first Mock interface, the second Mock interface, and the third Mock interface.
[0129] In some embodiments, in the case where the interface identifier of the Mock interface includes a persistent identifier, it is determined that the Mock data corresponding to the Mock interface is persistent data.
[0130] The interface identifier is used to uniquely identify the mock interface. Optionally, the interface identifier may include the name of the mock interface and its function. The persistence identifier is used to indicate that data persistence is required.
[0131] Understandably, when generating a mock interface based on the API documentation, the system determines whether the mock data corresponding to that interface is persistent based on the business information (or function) defined in the documentation. If so, a persistence flag is added to the interface identifier of the mock interface during the generation process. For example, if the business information corresponding to interface 1 defined in the API documentation is obtaining a random verification code, since the random verification code can be a random string and does not require data persistence, the mock data corresponding to interface 1 is not persistent. However, if the business information corresponding to interface 2 defined in the API documentation is adding user information, since the added user information requires data persistence, the mock data corresponding to interface 2 is persistent.
[0132] In this way, the processor can determine whether the Mock data corresponding to the Mock interface is persistent data based on whether the interface identifier of the Mock interface includes a persistent identifier.
[0133] S204. Store the Mock data corresponding to the candidate Mock interface in the target data table of the persistent storage medium.
[0134] The Mock data corresponding to the candidate Mock interface refers to the Mock data that needs to be obtained through the candidate Mock interface. For example, assuming that the request operation for the candidate Mock interface is a GET request operation, and this GET request operation is used to obtain user information through the candidate Mock interface, then the Mock data corresponding to the candidate Mock interface includes user information.
[0135] It is understood that the prerequisite for obtaining Mock data from persistent storage medium is that the Mock data exists in persistent storage medium. Therefore, in this embodiment of the application, before responding to the request operation, initialization is performed first to store the Mock data that needs to be obtained from persistent storage medium in persistent storage medium, so that when a request operation that needs to obtain Mock data is received later, the Mock data can be obtained from persistent storage medium.
[0136] Optionally, the Mock data corresponding to the candidate Mock interface can be stored in the target data table of the persistent storage medium, including the following implementation methods:
[0137] Implementation Method 1: The target data table includes a first data table and a second data table.
[0138] In some embodiments, in the case that the target data table includes a first data table and a second data table, as shown in Figure 3 The above step S204 can be implemented as:
[0139] S2041, in the case that the candidate Mock interface meets the RESTful standard, storing Mock data corresponding to the candidate Mock interface in the first data table.
[0140] In some embodiments, in the case that the RESTful standard identifier is included in the interface identifier of the candidate Mock interface, it is determined that the candidate Mock interface meets the RESTful standard. The RESTful standard identifier is used to indicate that the Mock interface needs to be called in the calling manner specified by the RESTful standard.
[0141] It can be understood that when generating the Mock interface according to the interface document, it is determined whether the interface defined in the interface document meets the RESTful standard according to the calling manner of the interface and the calling address of the interface, etc. If yes, the RESTful standard identifier is added in the interface identifier of the Mock interface when the Mock interface is generated according to the interface document. For example, if the calling manner of interface 1 defined in the interface document is GET request operation and the calling address is URL, it is determined that the interface meets the RESTful standard. If the calling manner of interface 2 is addUser and the calling address is the user-defined ID, it is determined that the interface does not meet the RESTful standard.
[0142] In this way, the processor can determine whether the candidate Mock interface meets the RESTful standard according to whether the RESTful standard identifier is included in the interface identifier of the candidate Mock interface.
[0143] For example, in the case that the candidate Mock interface meets the RESTful standard, assuming that the request operation for the candidate Mock interface is GET request operation, the GET request operation is used to obtain the first interface data through the candidate Mock interface, the Mock data corresponding to the candidate Mock interface is the first interface data, and the first interface data is stored in the first data table.
[0144] S2042, in the case that the candidate Mock interface does not meet the RESTful standard, storing Mock data corresponding to the candidate Mock interface in the second data table.
[0145] Exemplarily, in the case that the candidate Mock interface does not meet the RESTful standard, assuming that the request operation for the candidate Mock interface is a GET request operation, the GET request operation is used to obtain the second interface data through the candidate Mock interface, and the Mock data corresponding to the candidate Mock interface is the second interface data, the second interface data is stored in the second data table.
[0146] It can be understood that, by judging whether the candidate Mock interface meets the RESTful standard, the Mock data corresponding to the candidate Mock interface is respectively stored in different data tables, and the primary keys of the different data tables are different. In this way, according to the characteristics of the Mock interface, the Mock data corresponding to the Mock interface is respectively stored, which is convenient for storage and management, and facilitates searching.
[0147] Exemplarily, as shown in Figure 4 For example, the process of initializing the persistent storage medium can be implemented as the following steps in the manner provided by the above steps S201-S204, and the target data table includes the first data table and the second data table.
[0148] Sa1, check whether the to-be-created data table exists in the persistent storage medium.
[0149] The to-be-created data table is a data table that has not been created in the target data table. It can be understood that, since the target data table includes the first data table and the second data table, when step Sa1 is performed, there can be the following cases: the first data table and the second data table have both been created; or, any one of the first data table or the second data table has been created; or, the first data table and the second data table have not been created, therefore, the above to-be-created data table is the data table that has not been created in the target data table (the first data table and the second data table). Exemplarily, assuming that the first data table in the target data table has been created and the second data table has not been created, the to-be-created data table is the second data table; or, assuming that the first data table and the second data table in the target data table have not been created, the to-be-created data table is the first data table and the second data table.
[0150] If yes, the following step Sa3 is performed.
[0151] If no, the following step Sa2 is performed.
[0152] Sa2, create the to-be-created data table.
[0153] Specifically, the first data table is created if the first data table does not exist in the persistent storage medium; the second data table is created if the second data table does not exist in the persistent storage medium. The first data table and the second data table are created if the first data table and the second data table do not exist in the persistent storage medium.
[0154] Sa3, traversing the Mock interface of the browser page.
[0155] Sa4, judging whether the traversal is ended.
[0156] If yes, the initialization process is ended.
[0157] If no, the following step Sa5 is executed.
[0158] Sa5, judging whether the Mock data corresponding to the Mock interface currently accessed is persistent data.
[0159] If no, the step Sa4 is returned, and the next Mock interface is accessed.
[0160] If yes, the following step Sa6 is executed.
[0161] Sa6, judging whether the Mock interface currently accessed meets the RESTful standard.
[0162] If yes, the following step Sa7 is executed.
[0163] If yes, the following step Sa8 is executed.
[0164] Sa7, storing the Mock data corresponding to the Mock interface currently accessed in the first data table, and returning the step Sa4 to continue accessing the next Mock interface until the traversal of all Mock interfaces is ended.
[0165] Sa8, storing the Mock data corresponding to the Mock interface currently accessed in the second data table, and returning the step Sa4 to continue accessing the next Mock interface until the traversal of all Mock interfaces is ended.
[0166] Implementation mode two, the target data table includes a third data table.
[0167] In some embodiments, in the case that the target data table includes a third data table, the Mock data corresponding to the candidate Mock interface is stored in the third data table.
[0168] It can be understood that the Mock data corresponding to the candidate Mock interface can be stored in the third data table (without considering whether the candidate Mock interface meets the RESTful standard) in the embodiments of the present application, so that the process of the response request operation can be simplified without judging whether the RESTful standard is met in the subsequent response request operation process.
[0169] For example, as shown in Figure 5 The process of initializing the persistent storage medium can be implemented as the following steps, taking the method provided in the second implementation manner above as an example.
[0170] Sb1, checking whether the third data table exists in the persistent storage medium.
[0171] Sb2, if not, creating the third data table.
[0172] Sb3, if yes, traversing the Mock interface of the browser page.
[0173] Sb4, judging whether the traversal is ended.
[0174] If yes, ending the initialization process.
[0175] If no, executing the following step Sb5.
[0176] Sb5, judging whether the Mock data corresponding to the Mock interface currently accessed is persistent data.
[0177] If no, returning to step Sb4 to continue to access the next Mock interface.
[0178] If yes, executing the following step Sb6.
[0179] Sb6, storing the Mock data corresponding to the Mock interface currently accessed in the third data table, and returning to step Sb4 to continue to access the next Mock interface until the traversal of all Mock interfaces is ended.
[0180] II. Process of response request operation
[0181] In some embodiments, as shown in Figure 6 The process of response request operation can be implemented as the following steps.
[0182] S301, receiving a read request operation for a target Mock interface of a browser page.
[0183] The target Mock interface can be any Mock interface of the browser page. Optionally, the target Mock interface can be a candidate Mock interface, or the target Mock interface can not be a candidate Mock interface.
[0184] The read request operation is used to obtain data. Optionally, the read request operation includes a GET request operation.
[0185] In some embodiments, before step S301, the method further includes: in response to the received write request operation, writing Mock data in the storage space corresponding to the target Mock interface; and / or, in response to the received modification request operation, modifying the Mock data corresponding to the target Mock interface; and / or, in response to the received deletion request operation, deleting the Mock data corresponding to the target Mock interface, and the like. For details, refer to steps S401-S402, S501-S503, and S601-S603 in the following embodiments, which are not described here again.
[0186] It can be understood that, after the Mock data corresponding to the target Mock interface is added, modified, and / or deleted, the method provided by the embodiments of the present application can view the effect of the addition, modification, and / or deletion.
[0187] In some embodiments, step S301 can also be implemented as: after restarting the front-end device, receiving a read request operation for the target Mock interface of the browser page.
[0188] It can be understood that, compared with the method in the related art in which the data addition, deletion, and modification effect cannot be viewed after the front-end device is restarted, the present application can store the target Mock data after the addition, modification, or deletion operation in the persistent storage medium of the front-end device, so as to realize the persistence of the target Mock data. In this way, after the front-end device is restarted, when the request operation for the target Mock interface is received, the added target Mock data can be found from the persistent storage medium.
[0189] S302, in response to the read request operation, determining whether the Mock data corresponding to the target Mock interface is persistent data.
[0190] If not, perform S303;
[0191] If yes, perform S304.
[0192] As a possible implementation manner, the read request operation includes the interface identifier of the target Mock interface, and in the case that the interface identifier of the target Mock interface includes a persistent identifier, it is determined that the Mock data corresponding to the target Mock interface is persistent data.
[0193] S303, returning the preset Mock data to the target Mock interface.
[0194] The pre-stored Mock data refers to randomly generated Mock data according to the data type agreed in the interface document of the target Mock interface.
[0195] For example, if the business corresponding to the target Mock interface is to obtain a random verification code, the format of the random verification code is a number, and a random number is returned to the target Mock interface as the verification code in response to the read request operation.
[0196] It can be understood that if the Mock data corresponding to the target Mock interface is not persistent data, a random string can be generated according to the data type agreed in the interface document of the target Mock interface and returned to the target Mock interface, without the need to search in the persistent storage medium.
[0197] S304, searching for the target Mock data corresponding to the target Mock interface from the persistent storage medium, and returning the target Mock data to the target Mock interface.
[0198] In some embodiments, the read request operation includes a call address of the target Mock interface (the call address of the target Mock interface refers to the address of the resource called by the target Mock interface), and thus searching for the target Mock data corresponding to the target Mock interface from the persistent storage medium includes searching for the target Mock data from the persistent storage medium according to the call address of the target Mock interface. Optionally, the call address of the target Mock interface can be a URL, or the call address of the target Mock interface can be a custom ID. For example, if the call address of the target Mock interface is "http: / / xxx.x.x.x / xx", the processor searches for "http: / / xxx.x.x.x / xx" in the persistent storage medium, and the Mock data corresponding to "http: / / xxx.x.x.x / xx" is taken as the target Mock data.
[0199] It can be understood that the Mock data is stored in the persistent storage medium of the front-end device in the embodiments of the application, so as to realize the persistence of the Mock data, and thus, in the process of responding to the request operation, if the Mock data corresponding to the target Mock interface is persistent data, the target Mock data is searched from the persistent storage medium in response to the read request operation for the target Mock interface.
[0200] In some embodiments, the persistent storage medium includes a target data table for storing Mock data, and the step S304 can be implemented by searching for the target Mock data corresponding to the target Mock interface from the target data table of the persistent storage medium.
[0201] As a possible implementation, in the case that the target data table includes a first data table and a second data table, the step S304 can be implemented as the following steps:
[0202] Step c1, if the target Mock interface meets the RESTful standard, searching the target Mock data corresponding to the target Mock interface from the first data table.
[0203] Step c2, if the target Mock interface does not meet the RESTful standard, searching the target Mock data corresponding to the target Mock interface from the second data table.
[0204] It can be understood that, by judging whether the target Mock interface meets the RESTful standard, the embodiments of the present application can improve the searching efficiency by searching from different data tables respectively.
[0205] As another possible implementation, in the case that the target data table includes a third data table, the step S304 can be implemented as: searching the target Mock data corresponding to the target Mock interface from the third data table.
[0206] It can be understood that, in the above implementation, without judging whether the target Mock interface meets the RESTful standard, the target Mock data corresponding to the target Mock interface is searched from the third data table, which can simplify the process of responding to the request operation.
[0207] In some embodiments, in the case that the read request operation is successfully responded, a normal status code and the target Mock data are returned to the target Mock interface.
[0208] The read request operation successfully responded means that the target Mock data corresponding to the target Mock interface can be found in the persistent storage medium.
[0209] The status code is used to represent the numerical code of the HTTP response status. The normal status code means the status code of the successfully responded request operation. For example, the normal status code can be 200, indicating that the request operation is successfully responded.
[0210] For example, in the case that the read request operation for the target Mock interface is successfully responded, if the target Mock data corresponding to the target Mock interface is book information, the data returned to the target interface is “200” + “book information”.
[0211] In some other embodiments, in the case that the read request operation is not successfully responded, the exception reason of the read request operation is returned to the target Mock interface.
[0212] In this context, "read request operation failed to respond" means that the target Mock data corresponding to the target Mock interface was not found in the persistent storage medium.
[0213] The above exception reasons are used to indicate why a read request operation failed to respond. For example, reasons for a read request operation failing to respond include, but are not limited to, the following: a syntax error in the read request operation, the requested resource not existing, and a server exception.
[0214] Optionally, the exception reason for the above read request operation may include an exception status code. An exception status code refers to a status code indicating that the request operation did not respond successfully. For example, exception status codes may be as shown in Table 5 below.
[0215] Table 5
[0216]
[0217] For example, if a read request to a target Mock interface fails to respond, and the target Mock data corresponding to the target Mock interface does not exist, the data returned to the target interface is "404", indicating that the resource requested by the request operation does not exist. It is understood that, compared to related technologies that can only simulate scenarios where request operations succeed, this application embodiment can also simulate scenarios where request operations fail to respond by simulating exception status codes and exception reasons. This allows for more comprehensive debugging of the front-end development interface and improves front-end development efficiency.
[0218] In some embodiments, the target Mock data can be Mock data stored in persistent storage during the initialization process; or, the target Mock data can be Mock data added by the user; or, the target Mock data can be Mock data modified from the Mock data corresponding to the target Mock interface, etc. It is understood that this application embodiment does not limit the target Mock data. Regardless of what operation is performed on the Mock data corresponding to the target Mock interface before step S301, the operated Mock data can be stored in persistent storage. Thus, compared to the situation in related technologies where the data on the browser page returns to its initial state (e.g., the initial state can be data zeroing) upon browser refresh or restart, this application embodiment, by storing the target Mock data in persistent storage, ensures that when subsequent requests (including read requests, modification requests, and deletion requests) are received for the target Mock interface, the target Mock data can still be found in persistent storage.
[0219] As one possible implementation, such as Figure 7As shown, before step S301, the method further includes the following steps:
[0220] S401, receiving a write request operation for a target Mock interface.
[0221] The write request operation is used to write data. Optionally, the write request operation includes a POST request operation.
[0222] S402, in response to the write request operation, storing the target Mock data in the persistent storage medium.
[0223] In some embodiments, the write request operation includes: a call address of the target Mock interface and target Mock data corresponding to the target Mock interface; thus, in response to the write request operation, storing the target Mock data in the persistent storage medium includes: storing the target Mock data in a position indicated by the call address of the target Mock interface in the persistent storage medium. For example, if the call address of the target Mock interface is "http: / / xxx.x.x.x / xx" and the target Mock data corresponding to the target Mock interface is "information of book D", the processor finds "http: / / xxx.x.x.x / xx" in the persistent storage medium and stores "information of book D" in the position indicated by "http: / / xxx.x.x.x / xx".
[0224] It can be understood that, based on S401-S402, the target Mock data found through steps S301-S304 is new Mock data. Thus, compared with the method in the related art, which cannot view the effect of new data, the embodiments of the present application can store the new target Mock data in the persistent storage medium of the front-end device, so as to realize the persistence of the target Mock data. Thus, when a request operation (including a read request operation, a modification request operation, and a deletion request operation, etc.) for the target Mock interface is received subsequently, the new target Mock data can be found in the persistent storage medium.
[0225] In some embodiments, step S402 can be implemented as: in the case that the Mock data corresponding to the target Mock interface is persistent data, in response to the write request operation, storing the target Mock data in the persistent storage medium.
[0226] In some embodiments, the persistent storage medium includes a target data table, and step S402 can be implemented as: storing the target Mock data in the target data table of the persistent storage medium.
[0227] As a possible implementation, in a case where the target data table includes a first data table and a second data table, S402 can be implemented as follows: if the target Mock interface meets the RESTful standard, storing the target Mock data in the first data table; and if the target Mock interface does not meet the RESTful standard, storing the target Mock data in the second data table.
[0228] It can be understood that, by judging whether the target Mock interface meets the RESTful standard, the embodiments of the present application store the newly added Mock data in the corresponding data table, which facilitates storage and management, and facilitates searching.
[0229] As another possible implementation, in a case where the target data table includes a third data table, S402 can be implemented as follows: storing the target Mock data in the third data table.
[0230] It can be understood that, the embodiments of the present application can store the newly added Mock data in the third data table (without considering whether the Mock interface meets the RESTful standard), so that, in the subsequent response request operation process, it is not necessary to judge whether the RESTful standard is met, and the response request operation process can be simplified.
[0231] In some embodiments, in a case where the write request operation is successfully responded, a normal status code and the newly added target Mock data are returned to the target Mock interface.
[0232] The write request operation successfully responded means that the target Mock data is successfully stored in the persistent storage medium.
[0233] For example, in a case where the write request operation for the target Mock interface is successfully responded, if the target Mock data corresponding to the target Mock interface is the information of a book D; the information of the book D is stored in the persistent storage medium, and "200" + "the newly added information of the book D" is returned to the target Mock interface.
[0234] In other embodiments, in a case where the write request operation is not successfully responded, an exception reason of the write request operation is returned to the target Mock interface.
[0235] The write request operation is not successfully responded means that the target Mock data is not successfully stored in the persistent storage medium.
[0236] The exception reason is used to indicate the reason why the write request operation is not successfully responded. Optionally, the exception reason of the write request operation can include an exception status code as shown in Table 5.
[0237] In some embodiments, the method further includes modifying the target Mock data corresponding to the target Mock interface. For example, as shown in Figure 8 the method can be implemented as the following steps:
[0238] S501, receiving a modification request operation for the target Mock interface.
[0239] The modification request operation is used to modify the data. Optionally, the modification request operation includes a PUT request operation.
[0240] S502, in response to the modification request operation, searching for the target Mock data from the persistent storage medium and modifying the target Mock data.
[0241] In some embodiments, the modification request operation includes the call address of the target Mock interface and the modified target Mock data corresponding to the target Mock interface. Thus, in response to the modification request operation, searching for the target Mock data from the persistent storage medium and modifying the target Mock data includes: searching for the target Mock data from the persistent storage medium according to the call address of the target Mock; and replacing the target Mock data corresponding to the target Mock interface with the modified target Mock data.
[0242] For example, if the call address of the target Mock interface is “http: / / xxx.x.x.x / xx” and the modified target Mock data corresponding to the target Mock interface is the type of book D is “B type”, the processor searches for “http: / / xxx.x.x.x / xx” in the persistent storage medium and modifies the type of book D corresponding to “http: / / xxx.x.x.x / xx” from “A type” to “B type”.
[0243] In some embodiments, the step S502 can be implemented as: in the case that the Mock data of the target Mock interface is persistent data, in response to the modification request operation, searching for the target Mock data from the persistent storage medium and modifying the target Mock data.
[0244] In some embodiments, the persistent storage medium includes a target data table, and the S502 can be implemented as: searching for the target Mock data from the target data table of the persistent storage medium and modifying the target Mock data.
[0245] As a possible implementation manner, in a case where the target data table includes a first data table and a second data table, S502 can be implemented as follows: if the target Mock interface meets the RESTful standard, the target Mock data is searched from the first data table, and the target Mock data is modified; if the target Mock interface does not meet the RESTful standard, the target Mock data is searched from the second data table, and the target Mock data is modified.
[0246] As another possible implementation manner, in a case where the target data table includes a third data table, S502 can be implemented as follows: the target Mock data is searched from the third data table, and the target Mock data is modified.
[0247] S503, the modified target Mock data is stored and returned to the target Mock interface.
[0248] In some embodiments, the processor stores the modified target Mock data in the persistent storage medium, so that in a subsequent response request operation process, the modified target Mock data can be read from the persistent storage medium; or the modified target Mock data can be modified or deleted in the persistent storage medium.
[0249] In some embodiments, in a case where the modification request operation is successfully responded, a normal status code and the modified target Mock data are returned to the target Mock interface.
[0250] The modification request operation successfully responded means that the target Mock data in the persistent storage medium is successfully modified.
[0251] For example, in a case where the modification request operation for the target Mock interface is successfully responded, if the modified target Mock data corresponding to the target Mock interface is a book D of a type of "B class"; the target Mock data is searched in the persistent storage medium, the type of the book D is modified from "A class" to "B class", and "200" + "modified target Mock data" is returned to the target Mock interface.
[0252] In some other embodiments, in a case where the modification request operation is not successfully responded, an exception reason of the modification request operation is returned to the target Mock interface.
[0253] The modification request operation is not successfully responded means that the target Mock data in the persistent storage medium is not successfully modified.
[0254] The abnormal reason is used to identify the reason for the unsuccessful response of the modification request operation. Optionally, the abnormal reason of the modification request operation can include an abnormal status code as shown in Table 5.
[0255] It can be understood that based on the scheme provided in steps S501-S503, the target Mock data in the persistent storage medium can be modified, and the modified target Mock data can be stored in the persistent storage medium. In this way, compared with the method in the related art, which cannot view the effect of the modified data, the modified target Mock data can be stored in the persistent storage medium of the front-end device, so that when a request operation (including a read request operation, a modification request operation, and a delete request operation) for the target Mock interface is subsequently received, the modified target Mock data can be found in the persistent storage medium.
[0256] In some embodiments, the method further includes deleting the target Mock data corresponding to the target Mock interface. For example, as shown in Figure 9 the following steps can be implemented:
[0257] S601, receiving a delete request operation for the target Mock interface.
[0258] The delete request operation is used to delete data. Optionally, the delete request operation includes a DELETE request operation.
[0259] S602, in response to the delete request operation, finding the target Mock data from the persistent storage medium and deleting the target Mock data.
[0260] In some embodiments, the delete request operation includes a calling address of the target Mock interface and target Mock data corresponding to the target Mock interface. In this way, in response to the delete request operation, finding the target Mock data from the persistent storage medium and deleting the target Mock data includes finding the target Mock data from the persistent storage medium according to the calling address of the target Mock and deleting the target Mock data.
[0261] For example, if the calling address of the target Mock interface is “http: / / xxx.x.x.x / xx” and the target Mock data corresponding to the target Mock interface is “information of book A”, the processor finds “http: / / xxx.x.x.x / xx” in the persistent storage medium and deletes the “information of book A” corresponding to “http: / / xxx.x.x.x / xx”.
[0262] In some embodiments, the step S602 can be implemented as: in the case that the Mock data of the target Mock interface pair is persistent data, in response to the delete request operation, searching for the target Mock data from the persistent storage medium and deleting the target Mock data.
[0263] In some embodiments, the target data table is included in the persistent storage medium, and the step S602 can be implemented as: searching for the target Mock data from the target data table of the persistent storage medium and deleting the target Mock data.
[0264] As a possible implementation, in the case that the target data table includes a first data table and a second data table, the step S602 can be implemented as: if the target Mock interface meets the RESTful standard, searching for the target Mock data from the first data table and deleting the target Mock data from the first data table; if the target Mock interface does not meet the RESTful standard, searching for the target Mock data from the second data table and deleting the target Mock data from the second data table.
[0265] As another possible implementation, in the case that the target data table includes a third data table, the step S602 can be implemented as: searching for the target Mock data from the third data table and deleting the target Mock data from the third data table.
[0266] S603, storing and returning the record of deleting the target Mock data to the target Mock interface.
[0267] The record of deleting the target Mock data refers to the Mock data corresponding to the target Mock interface in the persistent storage medium after the target Mock data is deleted.
[0268] In some embodiments, in the case that the delete request operation is successfully responded, a normal status code and the record of deleting the target Mock data are returned to the target Mock interface.
[0269] The successful response of the delete request operation refers to the successful deletion of the target Mock data in the persistent storage medium.
[0270] For example, in the case that the delete request operation for the target Mock interface is successfully responded, if the target Mock data corresponding to the target Mock interface is the information of the book D, the information of the book D is deleted in the persistent storage medium, and “200” + “the record of deleting the information of the book D” is returned to the target Mock interface.
[0271] In some other embodiments, in the case that the delete request operation is not successfully responded, the exception reason of the delete request operation is returned to the target Mock interface.
[0272] The deletion request operation unsuccessful response refers to that the target Mock data is not successfully deleted in the persistent storage medium.
[0273] The above exception reason is used to indicate the reason for the deletion request operation unsuccessful response. Optionally, the exception reason of the above deletion request operation can include an exception status code as shown in Table 5.
[0274] It can be understood that based on the scheme provided in steps S601-S602, the target Mock data in the persistent storage medium can be deleted, and the record of deleting the target Mock data is stored in the persistent storage medium. In this way, compared with the method in the related art, which cannot view the effect of deleting data, the embodiments of the present application can store the record of deleting the target Mock data in the persistent storage medium of the front-end device. In this way, when the subsequent target Mock interface request operation (including read request operation, modification request operation, and deletion request operation, etc.) is received, the processor cannot find the target Mock data in the persistent storage medium.
[0275] For ease of understanding, the method provided by the embodiments of the present application will be described below taking the request operation as an example, which includes a POST request operation, a PUT request operation, a GET request operation, and a GET request operation initiated after restarting the browser.
[0276] POST request operation: as shown in Figure 10 , the display of the front-end device displays a browser page, which is a page displaying book information. The current book information includes book A, book B, and book C. In response to the operation of the user clicking the add button, the page for adding book information as shown in Figure 11 is displayed to the user. After the user inputs the book information, the user clicks the save button to complete the operation of adding book information.
[0277] In this process, the interaction within the front-end device includes: in response to the user's click operation, the browser initiates a POST request operation for the first Mock interface (assuming the Mock interface for saving the button is the first Mock interface); the POST request operation includes the book information identifier (the book information identifier can be a URL or a custom ID, used to uniquely identify the storage address of the book information, such as https: / / xxx.xxx / xx) and the newly added book information (for example, adding information about book D); the processor receives the POST request operation for the first Mock interface and determines whether the first Mock interface is an interface that needs to be persisted with data; if not, it returns a predefined response (for example, a random string); if so, the processor searches for the book information identifier (for example, a URL or a custom ID) in the persistent storage medium and stores the newly added book information (for example, adding information about book D) at the storage location indicated by the book information identifier.
[0278] GET Request Operation: After completing the add operation, in response to the user clicking the book information button, the browser initiates a GET request operation to the second mock interface (assuming the mock interface for the book information button is the second mock interface). The GET request operation includes the book information identifier (the book information identifier can be a URL or a custom ID, used to uniquely identify the storage address of the book information, such as https: / / xxx.xxx / xx). The processor receives the GET request operation to the second mock interface and determines whether the second mock interface is an interface that requires data persistence. If not, it returns a predefined response (e.g., a random string) to the first mock interface. If so, the processor searches for the book information identifier (e.g., a URL or a custom ID) in the persistent storage medium and sends the book information to the first mock interface so that the browser displays the book information as shown in the image. Figure 12 The page showing book information includes books A, B, and C, as well as the newly added book D.
[0279] PUT request operation: such as Figure 13 As shown, the front-end device's monitor displays a browser page, which is a page displaying book information. The current book information includes books A, B, C, and D, with book D's type being "History". In response to the user clicking the edit button corresponding to book D, the following is displayed to the user: Figure 14 On the page shown, where you can modify book information, the user changes the type of book D to "novel". After modifying the book information, click the save button to complete the modification.
[0280] In the process, the interaction process inside the front-end device includes: in response to the click operation of the user, the browser initiates a PUT request operation for the third Mock interface (assuming that the Mock interface of the modification button is the third Mock interface); wherein the PUT request operation includes a book information identifier (the book information identifier can be a URL or a custom ID, which is used to uniquely identify the storage address of the book information, for example, https: / / xxx.x.x.x / xx) and modified book information (the type of book D is modified to "novel"); the processor receives the PUT request operation for the third Mock interface, and judges whether the third Mock interface is an interface that needs to be data-persistent; if not, a predefined response is returned to the third Mock interface; if yes, the processor finds the book information identifier (for example, the URL or the custom ID) in the persistent storage medium, and modifies the book information, modifies the type of book D to "novel", and stores the modified book information in the storage location indicated by the book information identifier.
[0281] Re-initiating the GET request operation after restarting the browser: after the modification operation is performed, the user closes the browser and reopens it, and in response to the user's operation of clicking the book information button, the browser initiates a GET request operation for the second Mock interface (assuming that the Mock interface of the book information button is the second Mock interface); wherein the GET request operation includes a book information identifier (the book information identifier can be a URL or a custom ID, which is used to uniquely identify the storage address of the book information, for example, https: / / xxx.x.x.x / xx); the processor receives the GET request operation for the second Mock interface, and judges whether the second Mock interface is an interface that needs to be data-persistent; if not, a predefined response is returned to the second Mock interface; if yes, the processor finds the book information identifier (for example, the URL or the custom ID) in the persistent storage medium, and sends the book information to the second Mock interface, so that the browser displays the book information page as shown in Figure 15
[0282] As can be seen from the above examples, the Mock data is stored in the persistent storage medium of the front-end device, and the Mock data can be persistent without any support of the backend application, so that the Mock data can cover more scenarios that cannot be covered in related technologies, for example, the user can view the effect of the request operation; for example, the scenario of simulating the recovery after the request interruption (for example, the above example of re-initiating the GET request operation after restarting the browser). In this way, the user can more flexibly, conveniently and comprehensively debug the front-end development interface, and improve the front-end development efficiency.
[0283] As shown in the above embodiments, the processor 700 is configured to execute the method for processing Mock data of a front-end device provided in the above embodiments. The processor 700 includes a receiving module 701 and a searching module 702. In some other embodiments, the processor 700 further includes a determining module 703, a returning module 704 and an initializing module 705.
[0284] The receiving module 701 is configured to receive a Hypertext Transfer Protocol (HTTP) read request operation for a target Mock interface of a browser page.
[0285] The searching module 702 is configured to search, in response to the read request operation, target Mock data corresponding to the target Mock interface from a persistent storage medium, and return the target Mock data to the target Mock interface.
[0286] In a possible implementation, the searching module 702 is specifically configured to, in a case where the Mock data corresponding to the target Mock interface is persistent data, search, in response to the read request operation, the target Mock data corresponding to the target Mock interface from the persistent storage medium.
[0287] In another possible implementation, the read request operation includes an interface identifier of the target Mock interface, and the determining module 703 is configured to, in a case where the interface identifier of the target Mock interface includes a persistent identifier, determine that the Mock data corresponding to the target Mock interface is persistent data, where the persistent identifier is used to indicate that data persistence is required.
[0288] In another possible implementation, the returning module 704 is configured to, in a case where the read request operation is not successfully responded, return an exception reason of the read request operation to the target Mock interface, where the exception reason is used to indicate a reason why the read request operation is not successfully responded.
[0289] In another possible implementation, the persistent storage medium includes a first data table and a second data table, the first data table is used to store Mock data corresponding to an interface that meets a RESTful standard, and the second data table is used to store Mock data corresponding to an interface that does not meet the RESTful standard, and the searching module 702 is specifically configured to, if the target Mock interface meets the RESTful standard, search the target Mock data corresponding to the target Mock interface from the first data table, and if the target Mock interface does not meet the RESTful standard, search the target Mock data corresponding to the target Mock interface from the second data table.
[0290] In another possible implementation, the receiving module 701 is further configured to receive a modification request operation for the target Mock interface; the searching module 702 is further configured to search for the target Mock data from the persistent storage medium and modify the target Mock data in response to the modification request operation; and the storage module is configured to store the modified target Mock data and return the modified target Mock data to the target Mock interface.
[0291] In another possible implementation, the receiving module 701 is further configured to receive a write request operation for the target Mock interface; and the searching module 702 is further configured to store the target Mock data in the persistent storage medium in response to the write request operation.
[0292] In another possible implementation, the receiving module 701 is specifically configured to receive a hypertext transfer protocol read request operation for the target Mock interface of the browser page after the front-end device is restarted.
[0293] In another possible implementation, the initialization module 705 traverses Mock interfaces of the browser page and selects candidate Mock interfaces from the Mock interfaces; the Mock data corresponding to the candidate Mock interfaces is persistent data; and the initialization module 705 is configured to store the Mock data corresponding to the candidate Mock interfaces in the persistent storage medium.
[0294] In another possible implementation, the persistent storage medium includes a first data table and a second data table; the first data table is configured to store Mock data corresponding to interfaces that meet RESTful standards; the second data table is configured to store Mock data corresponding to interfaces that do not meet RESTful standards; and the initialization module 705 is configured to store the Mock data corresponding to the candidate Mock interfaces in the first data table in a case where the candidate Mock interfaces meet RESTful standards, and store the Mock data corresponding to the candidate Mock interfaces in the second data table in a case where the candidate Mock interfaces do not meet RESTful standards.
[0295] In another possible implementation, the persistent storage medium is a data cache device built in the browser.
[0296] Those skilled in the art can clearly understand the implementation of the above-described embodiments from the above description of the embodiments. For the convenience and brevity of description, only the division of the above-described functional modules is taken as an example for illustration. In actual applications, the above-described functions can be completed by different functional modules according to needs, that is, the internal structure of the processor is divided into different functional modules to complete all or part of the functions described above.
[0297] The embodiments of the present application further provide a computer readable storage medium. All or part of the processes in the above method embodiments can be directed by computer instructions to complete by relevant hardware, and the program can be stored in the computer readable storage medium. When the program is executed, the program can include the processes of the above method embodiments. The computer readable storage medium can be the memory of any of the above embodiments. The computer readable storage medium can also be an external storage device of the processor, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. Further, the computer readable storage medium can include both the internal storage unit of the processor and the external storage device. The computer readable storage medium is used to store the computer program and other programs and data required by the processor. The computer readable storage medium can also be used to temporarily store data that has been output or will be output.
[0298] The embodiments of the present application further provide a computer program product, which contains a computer program, and when the computer program product runs on a computer, the computer executes the method for mocking data of a processing front-end device provided in any of the above embodiments.
[0299] Although the present application is described herein in conjunction with specific embodiments thereof, numerous modifications and variations are possible in light of the above teachings without departing from the spirit and scope of the application. Accordingly, the description and drawings are to be regarded as illustrative in nature and are not to be taken as limiting the scope of the application as set forth in the appended claims. It will be apparent to those skilled in the art that various modifications and variations can be made to the present application without departing from the spirit or scope of the application. Thus, it is intended that the present application cover modifications and variations of this application provided they come within the scope of the appended claims and their equivalents.
[0300] Although the present application is described herein in conjunction with specific embodiments thereof, numerous modifications and variations are possible in light of the above teachings without departing from the spirit and scope of the application. Accordingly, the description and drawings are to be regarded as illustrative in nature and are not to be taken as limiting the scope of the application as set forth in the appended claims. It will be apparent to those skilled in the art that various modifications and variations can be made to the present application without departing from the spirit or scope of the application. Thus, it is intended that the present application cover modifications and variations of this application provided they come within the scope of the appended claims and their equivalents.
[0301] The above merely provides the specific implementation of the present application, but the protection scope of the present application is not limited to this. Any change or replacement within the technical scope disclosed by the present application should be covered in the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.
Claims
1. A method for processing Mock data from a front-end device, characterized in that, The front-end device includes: a processor, a display, and a persistent storage medium. The display shows a browser page. The method is applied to the processor, and the method includes: Receive read request operations for the target Mock interface of the browser page; In response to the read request operation, the target Mock data corresponding to the target Mock interface is retrieved from the persistent storage medium, and the target Mock data is returned to the target Mock interface; the persistent storage medium includes a target data table, which is used to store Mock data; The target data table includes a first data table and a second data table; the first data table is used to store Mock data corresponding to interfaces that meet the RESTful standard; the second data table is used to store Mock data corresponding to interfaces that do not meet the RESTful standard. The step of responding to the read request operation by retrieving the target Mock data corresponding to the target Mock interface from the persistent storage medium includes: If the target Mock interface meets the RESTful standard, then the target Mock data corresponding to the target Mock interface is retrieved from the first data table; If the target Mock interface does not meet the RESTful standard, then the target Mock data corresponding to the target Mock interface is retrieved from the second data table.
2. The method according to claim 1, characterized in that, The step of responding to the read request operation by retrieving the target Mock data corresponding to the target Mock interface from the persistent storage medium includes: If the Mock data corresponding to the target Mock interface is persistent data, in response to the read request operation, the target Mock data corresponding to the target Mock interface is retrieved from the persistent storage medium.
3. The method according to claim 1 or 2, characterized in that, The read request operation includes: the interface identifier of the target Mock interface, and the method further includes: If the interface identifier of the target Mock interface includes a persistence identifier, the Mock data corresponding to the target Mock interface is determined to be persistent data; wherein, the persistence identifier is used to indicate that data persistence is required.
4. The method according to any one of claims 1 to 3, characterized in that, The method further includes: If the read request operation fails to respond, return an exception reason for the read request operation to the target Mock interface; the exception reason is used to indicate why the read request operation failed to respond.
5. The method according to claim 1 or 2, characterized in that, Before receiving a read request operation for the target Mock interface of the browser page, the method further includes: Receive modification request operations for the target Mock interface; In response to the modification request operation, the target Mock data is retrieved from the persistent storage medium, and the target Mock data is modified; the modified target Mock data is stored and returned to the target Mock interface.
6. The method according to claim 1 or 2, characterized in that, Before receiving a read request operation for the target Mock interface of the browser page, the method further includes: Receive write request operations for the target Mock interface; In response to the write request operation, the target Mock data is stored in the persistent storage medium.
7. The method according to claim 6, characterized in that, The operation of receiving a read request for the target Mock interface of the browser page includes: After restarting the front-end device, a read request operation is received for the target Mock interface of the browser page.
8. The method according to claim 1 or 2, characterized in that, Before receiving a read request operation for the target Mock interface of the browser page, the method further includes: Traverse the Mock interfaces of the browser page and select candidate Mock interfaces; wherein, the Mock data corresponding to the candidate Mock interfaces is persistent data; The Mock data corresponding to the candidate Mock interface is stored in the persistent storage medium.
9. The method according to claim 8, characterized in that, The persistent storage medium includes: a first data table and a second data table; the first data table is used to store Mock data corresponding to interfaces that meet the RESTful standard; the second data table is used to store Mock data corresponding to interfaces that do not meet the RESTful standard; storing the Mock data corresponding to the candidate Mock interfaces in the persistent storage medium includes: If the candidate Mock interface meets the RESTful standard, the Mock data corresponding to the candidate Mock interface is stored in the first data table; If the candidate Mock interface does not meet the RESTful standard, the Mock data corresponding to the candidate Mock interface will be stored in the second data table.
10. The method according to claim 1 or 2, characterized in that, The persistent storage medium is the browser's built-in data caching device.
11. A front-end device, characterized in that, The front-end device includes: a display, a persistent storage medium, and a processor, wherein the display displays a browser page, and the processor is configured to perform the method for processing Mock data of the front-end device as described in any one of claims 1 to 10.
12. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions that, when executed on a computer, cause the computer to perform the method for processing Mock data of a front-end device as described in any one of claims 1 to 10.
13. A computer program product, characterized in that, The computer program product includes computer instructions that, when executed on a computer, cause the computer to perform the method for processing Mock data of a front-end device as described in any one of claims 1 to 10.
Citation Information
Patent Citations
Front-end interface data simulation method, device and system
CN113050923A