Mocknode

a configurable mock server

https://github.com/ianunay/mock-node

Mocking server responses are fundamental in development and maintenance of web applications.

Most often these mocks end up as part of the application code. And we might find ourselves repeating the code for creating these mocks.

Mocknode provides an intuitive web interface to configure a mock http server, modify the routes handled and configure how the server responds to different requests on these routes.

mocknode configuration interface

Handles

There are three ways a route can be handled:

  1. Proxy — Proxies the request to an existing service
  2. Stub — A static response which you can manage in the ‘manage stubs’ link of the route
  3. Dynamic Stub — Responds with a configured stub if the condition defined evaluates to true

You can add the different possible responses in the manage stubs page and choose the stub that you want the route to return.

In cases where more control is needed i.e. different stubs have to be returned for the same route based on the request parameters, use dynamic stubs.

If “Dynamic stub” is the handle and the above dynamic route is selected. The incoming request is sampled for the matching conditions. These conditions are executed in a sandbox environment. Conditions are javascript expressions formed using the req object [this is a stripped off version of the standard Express JS request object].

HTTP API

Mocknode exposes a http api to control the configuration of the mock server. This same api is used by the browser client to configure the server.

You can use this http api to have a granular control of the server in your integration / end-to-end tests.

The endpoints list is available on the github readme.

Logging

Requests to mocknode are logged in two files:

  1. Access log — logs containing all requests to mocknode
  2. Change log — logs containing configuration change requests to mocknode

Mocknode is a fairly young project which I have used in a couple of scenarios. Please do comment on what features you’d like to see implemented.

Happy mocking!