imitate
imitate
is a REST API mocking tool. It offers a simple workflow for:
- Proxying an existing API;
- Caching requests into a persistent file;
- Using that file to stub the real API.
imitate
is useful for end-to-end testing, offline development, and other situations where you want to access a close (but no cigar) copy of your real REST API. It is agnostic to your choice of backend or frontend.
Installation
Install it like any other node package, if using inside a project:
$ npm install imitate
To use the command-line API (coming soon), install it globally:
$ npm install -g imitate
Usage
Node API
proxyServer
To instantiate a proxyServer:
var proxyServer = require('imitate').proxyServer;
var proxy = proxyServer({
output: 'endpoints.json',
url: 'https://api.github.com/',
});
This will start a proxyServer on http://localhost:4000
, which will return the results from pinging https://api.github.com/ while also writing them in a file called 'endpoints.json' in the current working directory. See below for additional options.
You can stop it like any other express
server:
proxy.close();
mockServer
To instantiate a mockServer:
var mockServer = require('imitate').mockServer;
var mock = mockServer({
input: 'endpoints.json',
});
This will start a mockServer on http://localhost:4000
, which will use endpoints.json
to imitate all the previously stored endpoints. See below for additional options.
You can stop it like any other express
server:
mock.close();
Command-line API
Coming soon!
Options
proxyServer
You can start a proxyServer
with the following options:
var proxyServer = require('imitate').proxyServer;
var proxy = proxyServer({
url: 'https://api.github.com/',
port: 4000,
host: 'localhost',
output: 'endpoints.json',
silent: false,
});
mockServer
You can start a mockServer
with the following options:
var mockServer = require('imitate').mockServer;
var proxy = mockServer({
port: 4000,
host: 'localhost',
input: 'endpoints.json',
silent: false,
});
License
MIT.