Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fetch-har

Package Overview
Dependencies
Maintainers
9
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fetch-har

Make a fetch request from a HAR file

  • 2.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
47K
decreased by-17.96%
Maintainers
9
Weekly downloads
 
Created
Source

fetch-har

Build

Make a fetch request from a HAR file

Installation

npm install --save fetch-har

Usage

const fetchHar = require('fetch-har');

// If executing from an environment without `fetch`, you'll need to polyfill
global.fetch = require('node-fetch');
global.Request = require('node-fetch').Request;

const har = {
  log: {
    entries: [
      {
        request: {
          headers: [
            {
              name: 'Authorization',
              value: 'Bearer api-key',
            },
            {
              name: 'Content-Type',
              value: 'application/json',
            },
          ],
          queryString: [{ name: 'a', value: 1 }, { name: 'b', value: 2 }],
          postData: {
            text: '{"id":8,"category":{"id":6,"name":"name"},"name":"name"}',
          },
          method: 'POST',
          url: 'http://httpbin.org/post',
        },
      },
    ],
  },
};

fetchHar(har)
  .then(request => request.json())
  .then(console.log);

fetchHar(har, userAgent) => Promise

  • har is a har file format.
  • userAgent is an optional user agent string to let you declare where the request is coming from.

Performs a fetch request from a given HAR file. HAR files can be used to list lots of requests but we only use the first from the log.entries array.

fetchHar.constructRequest(har, userAgent) => Request

  • har is a har file format.
  • userAgent is an optional user agent string to let you declare where the request is coming from.

We also export a 2nd function which is used to construct a Request object from your HAR.

This function is mainly exported for testing purposes but could be useful if you want to construct a request but do not want to execute it right away.

Credits

Sanjeet

License

ISC

FAQs

Package last updated on 05 Feb 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc