Front-end mocks are always an important part of the process. Let’s start by comparing a few common mock tools: JSON-server, MockJS, and easyMock. I also recommend Fig-Mock, a new native mockServer that combines the best of the previous mock tools. (If you like, you can go to Github or code cloud. If it helps you, don’t forget to star.)
1, the json – server
Json-server is a simple and easy to use mock tool. With jSON-Server installed, you can quickly start the mock service, and then configure the db.json file to use Postman for interface testing and Ajax requests.
Advantages: You do not need to configure routes.
Disadvantages: 1. You need to create db. Json data files by yourself, which is cumbersome to create data. 2. User-defined routes are inconvenient.
Application scenario: Suitable for the scenario where the data volume is small and routing and path comparison are regular.
2, mockjs
This is an old mock tool, the granddaddy of all mock tools. This mock tool is easy to use and can quickly generate mock data. It is well documented and has good sample code.
Pros: Mocks are handy for making data
Disadvantages: need to understand the front-end background code, need to configure their own routing
Application scenario: For those who understand back-end code, routing is complex.
3, easy to mock
The visual version of MockJS has the advantage of being simple to operate, but the disadvantage is that it needs to rely on the network environment, and also requires its own handwritten routing configuration
4. FIG – Mock
The new mock tool, nicknamed Fly brother, is not a very high star at github, but the tool is very practical, I believe it will be high star. Here is a grand introduction:
No manual manufacturing of data, no hand-written routing, and a few lines of data item configuration (with syntax hints at config) enable a full native mock service. In the case of complex routes, personalized configuration can be performed on the basis of automatically generated routes. Easy to use and flexible.
Advantages: A perfect combination of jSON-server automatic routing and MockJS to create data
The name FIG comes from config, which means that a complete mock service can be started with the simplest configuration of data items
Principle:
- Using MockJS to make fake data to generate JSON files,
- Express is used to host back-end services, respond to front-end requests, and manipulate JSON file data
Basic routes are automatically generated during this period, eliminating the trouble of configuring routes and making it easy to implement fully functional mocks without knowing the backend
Experience Address:
Making: github.com/wcc0077/fig… (It’s hard, but sometimes it doesn’t open…)
Yards cloud: gitee.com/wcc0077/fig… (domestic, speed bar drop ~)
If this project helps you, don’t forget star oh ~~