MoqHttp 2.0.1
dotnet add package MoqHttp --version 2.0.1
NuGet\Install-Package MoqHttp -Version 2.0.1
<PackageReference Include="MoqHttp" Version="2.0.1" />
<PackageVersion Include="MoqHttp" Version="2.0.1" />
<PackageReference Include="MoqHttp" />
paket add MoqHttp --version 2.0.1
#r "nuget: MoqHttp, 2.0.1"
#:package MoqHttp@2.0.1
#addin nuget:?package=MoqHttp&version=2.0.1
#tool nuget:?package=MoqHttp&version=2.0.1
MoqHttp
MoqHttp is a lightweight, fluent HTTP mocking and VCR library for .NET 10+. It allows you to easily spin up a local HTTP server to mock API responses or record real API interactions for consistent, fast, and offline-capable testing.
🚀 Quick Start (Traditional Mocking)
Mock any HTTP endpoint with a few lines of code:
using MoqHttp;
// 1. Create and start the server
using var mockServer = new HttpServer(5000);
mockServer.Run();
// 2. Configure an endpoint
mockServer.Config.Get("/api/data").Send("{\"status\": \"ok\"}", 200);
// 3. Your code makes a request to http://localhost:5000/api/data
var httpClient = new HttpClient();
var response = await httpClient.GetAsync("http://localhost:5000/api/data");
var contents = await response.Content.ReadAsStringAsync(); // "{\"status\": \"ok\"}"
📼 VCR Functionality (Record & Replay)
Eliminate network flakiness by recording real API responses once and replaying them in your tests.
Auto Mode (Recommended)
Automatically records if the cassette file is missing, otherwise replays from disk.
mockServer.Config
.Auto()
.FromFile("fixtures/github_user.json")
.ProxyTo("https://api.github.com");
mockServer.Run();
// First run: Captures real data from GitHub
// Subsequent runs: Instant playback from local file!
Advanced VCR Features
- Filtering: Record only specific paths or HTTP verbs.
- Transformation: Modify recorded responses on the fly (e.g., inject current timestamps).
- Advanced Matching: Match by query strings, headers, or request bodies.
✨ Key Features
- Zero Configuration: Starts in-process with minimal boilerplate.
- Fluent API: Intuitive, chainable syntax for configuring mocks.
- Standard-Compliant: Built on top of ASP.NET Core Kestrel.
- No Dependencies: Pure .NET library using
System.Text.Json. - Fast: VCR playback is 100x faster than real network calls.
📦 Installation
dotnet add package MoqHttp
For more documentation and examples, visit the GitHub Repository.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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. |
-
net10.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.