Version: 1.8.0

Intro

The project#

This project provides a mock server that can simulate multiple API behaviors. It can be added as a dependency of your project, and started simply running an NPM command.

It is simple and easy out-of-the-box, but very powerful and customizable using plugins.

Why a mock server?#

Controlling the responses of the api will improve the front-end development workflow, avoiding early dependencies with back-end. It also improves the testing and development of error cases or another cases that are commonly hard to reproduce with a real api.

Defining the api responses during the earliest phases of development will improve the communication among team members and align their expectations.

Working with Node.js, it integrates better in front-end projects as any other NPM dependency, and it will be easier for front-end developers to maintain the mocks.

Why "Mocks" in plural?#

As explained, the mocks-server can simulate multiple api behaviors and send different responses to the same request, so it is like we have different mock servers that we can change while running at our convenience.

How does it work?#

As input, it needs "fixtures", which are handlers for specific requests, and "behaviors", which are sets of "fixtures".

You can simulate all the api behaviors you need for your development or tests environments simply extending behaviors to change the response of some specific uris, even when the received request is exactly the same.

You can easily change the current behavior while the server is running, which will make your development or acceptance tests environments very much agile and flexible, and not api dependant.

Installation#

Add it to your dependencies using NPM:

npm i @mocks-server/main --save-dev

Add next script to your package.json file:

{
"scripts": {
"mocks" : "mocks-server"
}
}

Usage#

Now, you can start the Mocks Server with the command:

npm run mocks

Interactive CLI

Configuration#

Configure the server simply creating a file at the root folder of your project.

For changing settings (such as current behavior, delay time, etc.) while it is running, it is distributed with two plugins:

Customization#

The mocks-server is very customizable, and gives you the possibility of extend it with every new amazing feature you want: