Why mock data
Parallel development, improve efficiency
As we all know, a project development needs front-end + back-end cooperation to complete, and the back-end programmer needs to provide API interfaces for the front-end development siege lion, so that the front-end development siege lion can use these interfaces to achieve the expected functions of the project.
In general, when we develop projects, all teams carry out projects in parallel. In order to reduce the dependence and waiting between each link, we need to do some data simulation in each link to achieve the purpose of parallel development.
Therefore, in the early stage, both parties should first determine the URL path of API interface, request parameters and returned data structure at the fastest speed. After determination, both parties can go their separate ways to complete their own tasks:
- The back-end program that implements these interfaces internally is the implementation;
- Test students, according to the agreed parameters, write test cases and automatic test scripts, prepare for the next test;
- Start front-end development (website, mini program, APP) immediately with mock data.
After the formal API interface is developed, you only need to change the mock domain name in the front-end development into the development domain name to conduct joint debugging, without modifying any other front-end code.
Quick prototyping
There are also application scenarios, the customer is not clear requirements, temporarily for the background to develop into what style, there is no clue. Therefore, it is still difficult for the programmer to provide a formal interface. Now the project urgently needs to make the prototype of the front end first, so that everyone can experience online and adjust and modify it while experiencing.
How to Mock data
Build your own through NodeJS
Install Node.js, enable the local server fetch port http://localhost:8000 via http-server, and many of the popular mock data JS components, which essentially require you to start a Web server on your development site. Then your front-end accesses your local Web server. Mock data, interface addresses, and data structures are all maintained locally, which is not conducive to team assistance. Moreover, some front-end development (such as applets and IOS development) must support THE CALL address of API interface is HTTPS. So this method can only do some simple data mocks.
Mock data through an online platform
You don’t need to build any mock environment. You just need to access the online mock platform provided by others. You just need to register an account, fill in the ADDRESS of the API interface you expect, and the content returned by the overdue interface, and then call the data in the front end.
Easy-mock, fast-mock, MockHTTP, and mock modules provided by API factories are widely used
I have been using the mock module provided by THE API factory to do interface simulation, which is stable and fast (some others may need to climb the wall, so I recommend you to use the API factory, which can be used in a few simple steps
Step 1: Register an API factory account for free the day after tomorrow. After registration, you will have a cloud background (with complete functions, such as CMS, CRM and mall can be developed online, but we only need to use his mock module).
Step 2: Factory Settings on the left -> Module Management, enable the Mock module: refresh the background screen, under the system Settings menu, you can see the mock application menu.