Front-end separation--building front-end mock Server

Source: Internet
Author: User
Tags download redis

Mock: A mock, false

Mock server: Simulate a service, simulate a request, simulate false data

In order to better division of the front and back, the interface document is necessary, the front and rear end are written according to the interface document code, and then docking interface on the line.

However, the backend can not keep up with the front-end rhythm, interface can not keep up? Even if the interface to follow up, large back-end data can not keep up with what?

The first way to think of is to simulate the return data, according to the interface document definition of the return data format, create a new JSON folder, put a bunch of *.json files, like this:

Then request the JSON data, like this:

So in order to have data on the front end, there will be a lot of requests for JSON files. When the back-end interface, but also a next to the JSON request to the real interface name, which requires code to write the comparison specification, or interface is really uncomfortable docking, and in the modification of some complex logic where the time must be cautious, or only wait for the test to send a bug list.

JSON file simulation request for small projects is really very convenient, but the project is big, hundreds of interfaces or even more?

A bunch of JSON looked bored, not to mention the front and back docking.

So how to solve the separation before and after, save time, improve development efficiency, reduce front-end dependence on the back end?

That is to provide the front end with a web container that can be used locally, and this is the mock server.

What problems can mock server solve?

1, the interface document writing

2, according to the interface interception request, return the interface needs to return the result data

3. Easy to switch on and off line

What I'm going to use as a mockserver is rap, rap. Combined with team management, project management, document writing, Mock.js, visualization, interface Transition, document history version (like), Mock plug-in (online and offline switch just need to comment a line of code OK), support on-premises deployment.

So how do you deploy rap to the local? There is a deployment manual on the website.

I am here to deploy to a Windows environment.

There are two ways to deploy:

1. Use a compiled War package deployment (for students who want to deploy rap services only, without the need to develop custom features)

2, the use of self-compiled source code, development after deployment (need to configure the Java EE Development environment, suitable for students who want to study rap source, develop custom features)

I do not need to develop my own war package deployment.

Environment Required: Jdk,tomcat,mysql,redis

The first step: on the official website https://github.com/thx/RAP/releases The latest war package down, and then renamed to Root.war, put in Tomcat under the WebApps inside

Step two: Start Tomcat, the war package is automatically deployed to the folder root

Step three: Modify the database configuration file to open root Web-inf/classes/config.properties

Modify Jdbc.username= your database user name

Modify jdbc.password= your database password

Redis Port Number Default

Fourth Step: Installing Redis

http://www.redis.net.cn/tutorial/3503.html Download redis-2.45

Depending on your actual situation, select the 64bit content CP to the custom drive letter installation directory named Redis. such as G:\dev

Open a CMD window using the CD command to switch directories to C:\redis run redis-server.exe redis.conf .

If you want to be convenient, you can add the path of Redis to the environment variables of the system, so as to save the path again, the latter redis.conf can be omitted, if omitted, the default is enabled. After entering, the following interface is displayed:

At this time another cmd window, the original do not close, otherwise you will not be able to access the server.

Switch to the Redis directory to run the redis-cli.exe-h 127.0.0.1-p 6379 .

Set the key-value pair set MyKey ABC

Remove key value pair get MyKey

This means that the Redis installation is successful.

Fifth step: Turn on Tomcat and Redis, browser input: localhost:8080

Indicates that the deployment was successful. The default user of rap is admin, password is encrypted by double MD5, but is not normal encryption ...

So to login to the admin, you have to register a user, such as password set to 123456, open MySQL

Copy the password of the newly registered Dothin to admin, then Admin will be able to log in.

How to use rap, self-read rap tutorial

Front-end separation--building front-end mock Server

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.