Version: 1.9.0

Intro

The project#

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

Main features#

  • Multiple api behaviors: It allows to define different responses for the same route, and group them into different behaviors.
  • Multiple formats: Responses can be defined using json files or Javascript files. Definitions can be plain objects, and even Express middlewares can be used to send dynamic responses.
  • Multiple interfaces: Settings can be changed using the interactive CLI or the admin REST API. The CLI is perfect for development, and the API can be used in other scenarios, as the Cypress plugin does.

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, you can use:

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.

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.

Customization#

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