mockify
Mockify is the API mocking made easy.
Record and replay your API calls for tests or development.
Warning: mockify is still experimental not ready for production.
Installation
- From npm:
npm install -g mockify
- From source:
git clone https://github.com/gandi/mockify.git && cd mockifysudo npm link
Development
If you want to work on mockify, use Gulp tasks:
cd mockify# install dependenciesnpm installcd wwwbower installcd ..# in a first terminal, watch your app (lint all JS and build the webapp for each modification)./gulp watch# in a second one, start mockify./gulp start# Just type ./gulp to see all available tasks.
Open your browser at localhost:3000
How does it work?
Mockify is basicly a proxy manager, just follow those simple steps:
- Create a target toward the service to mock
- Enable it, the proxy will start
- Turn record mode on
- Make a bunch of api calls through the proxy
- Turn mock mode on
- Mockify now returns recorded requests
The proxy will record everything which passing through it and the mock will use this data to return exactly the same results, according HTTP verb, status, query parameters, etc.
Mockify uses a SQLite database to store data and spawn in-memory databases for mocking.
The different parts of mockify
{<5>}
Features
- Save query and response of API(s)
- Mock the exact same request with exact same results
Using mockify with the built-in webapp
{<6>}
Using mockify from the command line
You can fully use mockify only with a shell. Here a quick example.
$ mockify startmockify daemon has been started.$ mockify add-target 4000 http://jsonplaceholder.typicode.comThe target has been added.┌────┬──────┬─────────────────────────────────────┬───────────┬──────────┬─────────┬─────────┐│ Id │ Port │ Url │ Recording │ Proxying │ Mocking │ Enabled │├────┼──────┼─────────────────────────────────────┼───────────┼──────────┼─────────┼─────────┤│ 1 │ 4000 │ http://jsonplaceholder.typicode.com │ 1 │ false │ false │ false │└────┴──────┴─────────────────────────────────────┴───────────┴──────────┴─────────┴─────────┘$ mockify enable-target 1[proxy-out] Proxy listening on localhost:4000 and proxying http://jsonplaceholder.typicode.com$ mockify log# in another shell, type: curl localhost:4000/userslocalhost:4000/users -> jsonplaceholder.typicode.com/users^C$ mockify start-mock 1[mock-out] Mock listening on port 4000 and mocking the target ID: 1$ mockify log# in another shell, type: curl localhost:4000/users200 GET /users on localhost:4000^C$ mockify disable-target 1The target has been disabled.$ curl http://localhost:4000/userscurl: (7) Failed to connect to localhost port 4000: Connection refused
Just type mockify
to list all available commands.
Using mockify module from node.js
var mockify = ;/* All these methods return a promise: */// start mockify daemonmockifystart;// stop mockify daemonmockify;// list the daemon(s) statusmockifystatus;// send a ping to mockify to check if it is runningmockify;// start the httpserver which serves the webappmockify;// stop the httpservermockify;// list saved targetsmockify;// add a targetmockify;// remove a targetmockify;// start a proxy to the url of the target// (stop the mock if it was running)mockify;// start a mock to the url of the target// (stop the proxy if it was running)mockify;// disable proxy or mock of a targetmockify;// enable / disable the recording for a targetmockify;/* You can log all proxies / mocks output with the log method which returns an eventEmitter: */mockify;
Roadmap
- Customize recorded sessions (edit response and request content, status code, headers)
- Add delay for proxy responses to test unexpected scenarios
- Enhance webapp logs to keep track of history