xhr-proxy-plus
v0.0.22
Published
help proxy xhr, the same as axios interceptor
Downloads
26
Maintainers
Readme
Install
npm install xhr-proxy-plus
How to use ?
import { XhrProxy } from 'xhr-proxy-plus';
// start proxy xhr
const handle = new XhrProxy({
beforeHooks: {
open: (...p) => {
console.log('xhr.open params', ...p);
},
send: (...p) => {
console.log('xhr.send params', ...p);
console.log('xhr.send will stop executing');
// hook return false will stop xhr
return false;
}
},
afterHooks: {},
apiCallback: (r) => {
console.log('request message--->', r);
}
});
// cancel proxy
handle.unset();
console.log
xhr.open params GET /api/v1/query/goods true
xhr.send params {"name":""}
request message--->
{
"method": "GET",
"url": "/api/v1/query/goods",
"params": {
name: 'water',
},
"requestHeaders": {
"Accept": "application/json, text/plain, */*",
},
"body": null,
"requestStamp": 1597922785160,
"responseData": {
"code": 0,
"message": "ok",
"data": null
},
"responsHeaders": {
"content-type": "application/json; charset=UTF-8",
"date": "Thu, 20 Aug 2020 11:26:25 GMT",
},
"responsStamp": 1597922785301
}