Your Docusaurus site did not load properly.

A very common reason is a wrong site baseUrl configuration.

Current configured baseUrl = / (default value)

We suggest trying baseUrl =

Interactive CLI animation

Mocks Server

Node.js mock server

Multiple api behaviors

Define different responses for the same route (fixtures), and group them into different behaviors. Ensure that your API client is ready to handle all cases. Storing the different behaviors allows to use mocks-server both for development and testing phases.

Multiple formats

Define fixtures and behaviors using json files or JavaScript files. Define responses using plain objects, or even Express middlewares. Hot reload changes the responses in real time once files are changed.

Multiple interfaces

Change the current behavior of the server and other settings while it is running 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.

Developer friendly

The main distribution of mocks-server includes some preinstalled plugins for making easy to control the server while it is running, allowing to change the current behavior, to change the delay, etc.

Settings can be changed using an interactive CLI or using a REST API. This allows to use mocks-server both for development and testing phases easily.

It also includes hot-reloading, so the responses of the server will change while you change your fixtures files.

Easy to use

Install it and start it in seconds. Follow the tutorial to add fixtures and you'll have a simulated api in few minutes.

Create a configuration file, start it, and use the interactive CLI or the admin REST API for changing settings while it is running.
npm i --save-dev @mocks-server/main
// package.json
{
"scripts": {
"mocks": "mocks-server"
}
}

Flexible

Define fixtures for HTTP responses in JSON files, or as JavaScript objects.

Using the built-in fixtures handler, responses can be defined using static properties, or using Express middlewares for more complex scenarios.

If this is not enough, you can even add your own handlers to change the format in which you define the responses fixtures.
{
"id": "get-users-empty",
"url": "/api/users",
"method": "GET",
"response": {
"status": 200,
"body": []
}
}
const users = require("./db/users");
module.exports = {
id: 'get-users',
url: '/api/users',
method: 'GET',
response: (req, res) => {
res.status(200);
res.send(users);
},
}

Maintainable

Maintain your fixtures organized and group them in different behaviors.

Behaviors can be created extending from another ones, so you can modify or add new fixtures to the main behavior, and the rest of behaviors will inherit them.
[
{
"id": "standard",
"fixtures": ["get-user", "update-user"]
},
{
"id": "update-user-error",
"from": "standard",
"fixtures": ["update-user-error"]
}
]

Integrations

There are available packages for integrating the Mocks Server with other development tools.

For example, @mocks-server/cypress-commands allows to easily control the mock server from Cypress. Read the Cypress integration chapter for further info
describe("user with admin role", () => {
before(() => {
cy.mocksServerSetBehavior("admin-user");
cy.visit("/");
});
it("should see the users section link", () => {
cy.get("#users-section-link").should("be.visible");
});
});

Customizable

From defining fixtures using express middlewares to developing your own plugins or even adding new fixtures handlers, the mocks-server is very adaptable to achieve any project requirements.

Plugins from NPM or your own plugins can be added easily using the configuration file
class Plugin {
constructor(core) {
core.addSetting({
name: "traceBehaviors",
type: "boolean",
description: "Trace behaviors changes",
default: true
});
this._core = core;
this._onChangeMocks = this._onChangeMocks.bind(this);
this._onChangeSettings = this._onChangeSettings.bind(this);
}
// ...
}

Upcoming features

Administration web user interface, Chrome extension, Proxy fallback, Web Sockets, store your fixtures in a remote host, etc.

Check the GitHub project to stay up to date on what we are working.

Give it a star on GitHub