request-watcher
A tool that forwards network requests
Quick Start for using axios
install packages
$ npm install -g request-watcher-server$ npm install -D request-watcher$ npm install -D request-watcher-axios
start server
$ rws$ open http://localhost:2333
inject watcher code
const axios = const watcher = const axiosWatcher = axioswatcher
Quick Start for using fetch
install packages
$ npm install -g request-watcher-server$ npm install -D request-watcher$ npm install -D request-watcher-fetch
start server
$ rws$ open http://localhost:2333
inject watcher code
const watcher = const fetchWatcher = fetchwatcher
Install
$ npm install -g request-watcher-server$ npm install -D request-watcher
Usage
Start Server
The server requires node v7.6.0 or higher for ES2015 and async function support
Once you globally installed the request-watcher-server, you will get a global cmd request-watcher-server
and also rws
for short.
And then you can use the following cmd:
$ rws [-a 0.0.0.0] [-p 2333]
default address is 0.0.0.0:2333 you can use
rws -h
to get more help
Watch Request
const watcher = const watcherParams = username: 'username' appname: 'appname' labels: // e.g.// before send a request, emit the request to request-watcher-serverconst emitReq emitRes = const requestParams = url params headers method: 'POST' axios
Note that each time you watch a request, you need to use the
watcher
function to regenerate the matchingemitReq
andemitRes
watcherParams
watcherParams is an Object Containing the following properties
Args | Type | Description |
---|---|---|
origin | String (optional) | watcher origin |
username | String (required) | one of the request markers |
appname | String (required) | one of the request markers |
labels | [String] (optional) | add extra label to request to differentiate |
requestParams
requestParams is an Object Containing the following properties
Args | Type | Description |
---|---|---|
url | String (optional) | request url |
method | String (optional) | request method |
headers | Object (optional) | request headers |
params | Object (optional) | request params in body |
responseParams
responseParams is an Object Containing the following properties
Args | Type | Description |
---|---|---|
status | Integer (optional) | response status |
headers | Object (optional) | response headers |
data | Object (optional) | response data |
Watch Logger
You can just emit a log to the server, like bellow:
const emitLog = const loggerParams = title: 'logger' content: 'this is a log'
Notice! everytime you emit a logger need to regenerate a new emitLog function. It's Inconvenient(indeed it's for plugin using), thus we supply a more convenient way to do same thing:
// Only define onceconst watcherParams = labels: 'log'const logger = watcher // use everywhere// or
loggerParams
loggerParams is an Object Containing the following properties
Args | Type | Description |
---|---|---|
title | String (optional) | logger title |
content | Any (optional) | logger content |
Global Config
You can use watcher.global
to define global params, and thus you can just use watcher()
without passing params.
watcherglobalorigin = 'http://127.0.0.1:8080' // default is 'http://0.0.0.0:2333'watcherglobalusername = 'request-watcher' // default is 'username'watcherglobalappname = 'request-watcher-app' // default is 'appname' const emitReq emitRes = const emitLog =
Plugins
We support plugin to simplify the configs. And now we have these plugins:
Plugin Usage
Using axios for example:
const watcher = watcher
And then, you can just focus on your biz code without inserting redundant code before or after the ajaxing code.
Eggs
- Clicking the
Console
button outputs the data to the browser's console and obtains a global variable$it
pointing to that data.
Example
Refer to this example
Enjoy! :)