Vcr.HttpRecorder 3.1.4

dotnet add package Vcr.HttpRecorder --version 3.1.4
                    
NuGet\Install-Package Vcr.HttpRecorder -Version 3.1.4
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Vcr.HttpRecorder" Version="3.1.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Vcr.HttpRecorder" Version="3.1.4" />
                    
Directory.Packages.props
<PackageReference Include="Vcr.HttpRecorder" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Vcr.HttpRecorder --version 3.1.4
                    
#r "nuget: Vcr.HttpRecorder, 3.1.4"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Vcr.HttpRecorder@3.1.4
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Vcr.HttpRecorder&version=3.1.4
                    
Install as a Cake Addin
#tool nuget:?package=Vcr.HttpRecorder&version=3.1.4
                    
Install as a Cake Tool

Vcr.HttpRecorder

.NET HttpClient integration tests made easy.

HttpRecorder is an HttpMessageHandler that can record and replay HTTP interactions through the standard HttpClient . This allows the creation of HTTP integration tests that are fast, repeatable and reliable.

Interactions are recorded using the HTTP Archive format standard, so that they are easily manipulated by your favorite tool of choice.

License

πŸ“ This is a maintained fork of the original nventive/HttpRecorder.
It includes bug fixes, support for modern .NET versions, and new features like concurrent context support.

<details> <summary>πŸ“š Table of Contents</summary>

</details>

If you're using WebApplicationFactory, this is the simplest and most powerful way to enable automatic recording and replaying across all HttpClients:

[Fact]
public async Task MyApiTest()
{
    using var context = new HttpRecorderConcurrentContext((_, _) => new HttpRecorderConfiguration
    {
        Mode = HttpRecorderMode.Auto, // Automatically records or replays
    });

    var client = webAppFactory.WithWebHostBuilder(builder =>
    {
        builder.ConfigureTestServices(services =>
        {
            services.AddHttpRecorderConcurrentContextSupport(); // Injects the handler globally
        });
    }).CreateClient();

    var response = await client.GetAsync("/api/my-endpoint");

    Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}

βœ… No need to manually configure HttpClient

βœ… All HttpClients use the recorder automatically

βœ… .har files are stored per test method

βœ… Supports parallel test execution

Install via NuGet

Install-Package HttpRecorder

Using the Delegating Handler Manually

If you want to apply HttpRecorder to a specific HttpClient only β€” without affecting the global DI container β€” you can use the delegating handler directly:

var interactionPath = "fixtures/test.har";

var client = new HttpClient(new HttpRecorderDelegatingHandler(interactionPath)
{
    InnerHandler = new HttpClientHandler()
})
{
    BaseAddress = new Uri("https://reqres.in/")
};

This is useful if you need more granular control over which clients are recorded.

πŸ“ Tip: You can use CallerMemberName + CallerFilePath to automatically name har files per test.

Features

Modes
  • Auto (default): Replay if cassette exists, otherwise record

  • Record: Always record

  • Replay: Always replay (throws if file is missing)

  • Passthrough: Bypass recorder, make real requests

You can override the mode with the HTTP_RECORDER_MODE environment variable β€” useful in CI.

Matching Behavior

When replaying, HttpRecorder uses a rule-based matcher to determine which recorded response to return for a given request.

By default, if you don’t configure a matcher, it behaves exactly as if you had written:

matcher = RulesMatcher.MatchOnce
    .ByHttpMethod()
    .ByRequestUri(UriPartial.Path);

This means:

Requests are matched by HTTP method and the path part of the URI

Each recorded request is used once and in order

If your test sends two identical requests, both must have been recorded

If there are not enough matching requests in the .har file during replay, the test will fail.

Custom Matchers

You can customize the matching logic to match multiple times or add more rules β€” for example:

matcher = RulesMatcher.MatchMultiple
    .ByHttpMethod()
    .ByRequestUri(UriPartial.Path)
    .ByHeader("Authorization");
matcher = RulesMatcher.MatchOnce
    .ByHttpMethod()
    .ByRequestUri(UriPartial.Path)
    .ByContent(); // matches by binary content

You can also match by deserialized JSON:

matcher = RulesMatcher.MatchOnce
    .ByHttpMethod()
    .ByJsonContent<MyRequestDto>();

πŸ“ If none of the built-in rules suit your needs, you can implement a custom IRequestMatcher.

Anonymization

Mask sensitive fields before saving:

var anonymizer = RulesInteractionAnonymizer.Default
    .AnonymizeRequestHeader("Authorization");

External HAR Support

You can use .har files recorded with tools like:

  • Fiddler

  • Chrome DevTools

  • Postman

Just pass the file path into the handler.

Custom Storage

You can override how and where interactions are stored via IInteractionRepository.

Compared to WireMock

WireMock is a powerful tool, but sometimes it's more than you need β€” especially for simple, deterministic testing of external API calls.

Feature WireMock Vcr.HttpRecorder
Requires mock server βœ… ❌
Requires hand-written stubs βœ… ❌ (records real responses)
Easily test external API logic ⚠️ manual setup needed βœ… out of the box
Works with WebApplicationFactory ⚠️ extra wiring βœ… built-in support
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.1.4 2,019 9/19/2026
3.1.4-concurrent-contect-as... 48 6/13/2026
3.1.4-beta.16 62 9/18/2026
3.1.4-beta.12 61 9/16/2026
3.1.4-beta.10 182 6/30/2026
3.1.4-beta.6 120 5/18/2026
3.1.3 6,349 5/18/2026
3.1.3-beta.10 74 5/18/2026
3.1.3-beta.4 14,152 4/6/2025
3.1.3-beta.3 223 4/5/2025
3.1.3-beta.2 130 4/5/2025
3.1.3-beta.1 126 4/5/2025
3.1.2 5,659 4/5/2025
3.1.2-beta.1 131 4/5/2025
3.1.1 226 4/5/2025
3.1.1-beta.8 119 4/5/2025
3.1.1-beta.7 139 4/5/2025
3.1.1-beta.6 132 4/5/2025
3.1.1-beta.5 132 4/5/2025
3.1.1-beta.4 132 4/5/2025
Loading failed