https://github.com/shanamaid/xhr-proxy-plus
help proxy xhr, the same as axios interceptor
https://github.com/shanamaid/xhr-proxy-plus
http-record interceptor xhr xhr-interceptor xhr-proxy xmlhttprequest
Last synced: 7 months ago
JSON representation
help proxy xhr, the same as axios interceptor
- Host: GitHub
- URL: https://github.com/shanamaid/xhr-proxy-plus
- Owner: ShanaMaid
- License: mit
- Created: 2020-08-20T11:09:35.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-08-18T03:45:33.000Z (about 4 years ago)
- Last Synced: 2024-04-23T22:40:33.875Z (over 1 year ago)
- Topics: http-record, interceptor, xhr, xhr-interceptor, xhr-proxy, xmlhttprequest
- Language: JavaScript
- Homepage:
- Size: 41 KB
- Stars: 4
- Watchers: 4
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
xhr-proxy-plus
![]()
![]()
![]()
![]()
![]()
## Install
```
npm install xhr-proxy-plus
```## How to use ?
```js
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
```js
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](https://github.com/hiNISAL/any-xhr)