HTTP/REST API recorder and replayer
You can use it to mock API servers that are unstable/changing from time to time instead of creating mock response manually each time.
(Proxy support is through the npm package global-agent, read its github page for more infomation)
Usage scenario
- Record, finish tests and stop recording (responses will be saved)
+-------------+ +--------------------+ +--------------------------+| HTTP Client | => | Run it as Recorder | => | Target (e.g. API server) |+-------------+ +--------------------+ +--------------------------+
- Replay the test
+-------------+ +--------------------+| HTTP Client | => | Run it as Replayer |+-------------+ +--------------------+
- Check in the record file
<name>.json
(by default, it'sdefault.json
) to your version control, and you can always use step 2 to re-test your app/code, without any external server dependencies
Basic usage
Command line
Record:
(Default listening port is 43210)
rest-replayer record -t https://jsonplaceholder.typicode.com
- with proxy
GLOBAL_AGENT_HTTP_PROXY=http://proxy:port rest-replayer record -t https://jsonplaceholder.typicode.com
- debug with nodemon (Development only and if you are inside the code directory)
npm run nodemon:debug record -- -t https://jsonplaceholder.typicode.com
Replay:
rest-replayer replay
Command line help:
rest-replayer --help
Use as node.js module
let Runner = // option has properties that are the same a `yargs` argv// i.e. the property names are arguments key name camelizedlet option = name: 'demo' target: 'https://jsonplaceholder.typicode.com'let replayer = option printerreplayerreplayer