xhr-proxy-plus
TypeScript icon, indicating that this package has built-in type declarations

0.0.22 • Public • Published

xhr-proxy-plus

version license downloads downloads-month

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
}

Thanks

hiNISAL

Package Sidebar

Install

npm i xhr-proxy-plus

Weekly Downloads

1

Version

0.0.22

License

ISC

Unpacked Size

25.7 kB

Total Files

6

Last publish

Collaborators

  • shanamaid