HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulevcr-0.1.0GHC2024

VCR

Record and replay HTTP interactions

This module provides functionality for recording and replaying HTTP interactions using a tape. A tape represents a stored log of request/response pairs and can be operated in two modes:

  • AnyOrder (the default): Requests may be replayed in any order. In this mode the tape is interpreted as a mapping from requests to responses.

  • Sequential: Requests must be replayed in the order in which they were recorded. In this mode the tape is interpreted as a list of request/response pairs.

The module exports the following operations to work with tapes:

  • with - Replays previously recorded interactions and records new ones.

  • record - Records new interactions, overwriting any existing ones.

  • play - Replays previously recorded interactions and fails when a requested interaction is not found on the tape.

  • 2 types
  • 3 values
  • Packagevcr-0.1.0
  • Exports5
  • LanguageGHC2024
  • LicenceMIT
  • SourceVCR.hs

Types

2 declarations
datadata Tape
#

A Tape is used to record and replay HTTP interactions.

It consists of:

  • A file path to persist the tape to.

  • A mode that controls whether interactions are replayed sequentially or in any order.

  • A redact function that can modify HTTP requests (by default this redacts the Authorization header).

Constructors

Instances1IsString
datadata Mode
#

Represents the mode of operation for a tape.

Constructors

  • Sequential

    Requests must be replayed in the order in which they were recorded.

  • AnyOrder

    Requests may be replayed in any order.

Instances2Eq, Show
  • Eq ModeDefined in vcr-0.1.0 · VCR
  • Show ModeDefined in vcr-0.1.0 · VCR

Tape Operations

3 declarations
valuewith :: HasCallStack => Tape -> IO a -> IO a
#

Execute an action with the given tape in read-write mode.

  • Replay interactions that have been recorded earlier.

  • Record new interactions that do not yet exist on the tape.

Use with when you want to both replay and record interactions.

valuerecord :: Tape -> IO a -> IO a
#

Execute an action with the given tape in write mode.

  • Overwrite interactions that have been recorded earlier.

  • Record new interactions that do not yet exist on the tape.

Use record when you want to update a tape with new responses, replacing any existing interactions for a given request.

valueplay :: HasCallStack => Tape -> IO a -> IO a
#

Execute an action with the given tape in read mode.

  • Replay interactions that have been recorded earlier.

  • Fail on new interactions that do not yet exist on the tape.

Use play when you want to test against recorded responses while at the same time also deny real HTTP requests for interactions that have not been recorded.