Wrapper for request module that saves all traffic as a HAR file, useful for auto mocking a client
npm install request-capture-har> Wrapper for request module that saves all network traffic data as a HAR file.
 
Compatibility
request >= 2.81.0 recommended, as it has much more detailed timings via timingPhases.
request >= v2.75.0 required, at a minimum.
``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.clearHar();
`
This repo is a fork of larsthorup's 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.
!image
_Above is a HAR captured by using request-capture-har from within npm to capture an npm install`._