fromTraffic

Generate request handlers from a HAR file.

The fromTraffic function generates request handles from the given HAR document.

Call signature

function fromTraffic(
  archive: Har.Har,
  mapFn?: (entry: Har.Entry) => Har.Entry | undefined
): RequestHandler[]

Usage

The fromTraffic function accepts a parsed HAR file, which is a plain JavaScript object. Depending on your project, you can either import the *.har file directly, or read it from the file system and parse it via JSON.parse().

import { fromTraffic } from '@mswjs/source/traffic'
import har from './api.har'
 
const handlers = fromTraffic(har)

Network archive (HAR)

Generate request handlers from HAR files.