https://github.com/paulirish/request-capture-har
Wrapper for request module that saves all traffic as a HAR file.
https://github.com/paulirish/request-capture-har
har request
Last synced: over 1 year ago
JSON representation
Wrapper for request module that saves all traffic as a HAR file.
- Host: GitHub
- URL: https://github.com/paulirish/request-capture-har
- Owner: paulirish
- License: mit
- Created: 2016-08-28T01:30:08.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2017-03-27T19:35:56.000Z (over 9 years ago)
- Last Synced: 2024-10-19T12:32:18.387Z (almost 2 years ago)
- Topics: har, request
- Language: JavaScript
- Homepage:
- Size: 723 KB
- Stars: 41
- Watchers: 3
- Forks: 7
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# request-capture-har
> Wrapper for [`request` module](https://www.npmjs.com/package/request) that saves all network traffic data as a HAR file.
[](https://travis-ci.org/paulirish/request-capture-har) [](https://npmjs.org/package/request-capture-har)
**Compatibility**
request >= 2.81.0 recommended, as it has much more detailed timings via `timingPhases`.
request >= v2.75.0 required, at a minimum.
### Usage
```js
// wrap around your request module
const RCH = require('request-capture-har');
const requestCaptureHar = new RCH(require('request'));
// ...
// `requestCaptureHar.request` is your `request` module's API.
// ...
requestCaptureHar.request(uri, options, callback);
// Save HAR file to disk
requestCaptureHar.saveHar(`network-waterfall_${new Date().toISOString()}.har`);
// You can also clear any collected traffic
requestCaptureHar.clear();
```
This repo is a fork of [larsthorup's `node-request-har-capture`](https://github.com/larsthorup/node-request-har-capture). Instead of monkey-patching `request-promise`, the API allows you to pass in the general `request` module. We also added better support for transfer timings.

_Above is a HAR captured by using `request-capture-har` from within `npm` to capture an `npm install`._
### Background
This is especially useful for capturing all test traffic from your back-end test suite, for doing auto mocking in your front-end test suite. See this project for an example: https://github.com/larsthorup/http-auto-mock-demo. Blog post about this technique: http://www.zealake.com/2015/01/05/unit-test-your-service-integration-layer/