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.
- 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
- 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.
Add it to your dependencies using NPM:
Add next script to your
Now, you can start the Mocks Server with the command:
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:
- Interactive command line interface, which is very useful in local environments for development.
- REST API which is very useful to change behaviors from E2E tests, for example, as the Cypress plugin does.
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.
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.
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.
The mocks-server is very customizable, and gives you the possibility of extend it with every new amazing feature you want: