GennadyGS.WireMock.Net.Routing 1.0.1

dotnet add package GennadyGS.WireMock.Net.Routing --version 1.0.1
                    
NuGet\Install-Package GennadyGS.WireMock.Net.Routing -Version 1.0.1
                    
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="GennadyGS.WireMock.Net.Routing" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="GennadyGS.WireMock.Net.Routing" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="GennadyGS.WireMock.Net.Routing" />
                    
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 GennadyGS.WireMock.Net.Routing --version 1.0.1
                    
#r "nuget: GennadyGS.WireMock.Net.Routing, 1.0.1"
                    
#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 GennadyGS.WireMock.Net.Routing@1.0.1
                    
#: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=GennadyGS.WireMock.Net.Routing&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=GennadyGS.WireMock.Net.Routing&version=1.0.1
                    
Install as a Cake Tool

WireMock.Net.Routing

NuGet Build .NET License

WireMock.Net.Routing extends WireMock.Net with modern, minimal-API-style routing for .NET. It provides extension methods for expressive, maintainable, and testable HTTP routing, inspired by ASP.NET Core Minimal APIs.


Motivation

While WireMock.Net is a powerful tool for HTTP mocking in .NET, its native API for defining routes and request handlers can be verbose and require significant boilerplate. Setting up even simple endpoints often involves multiple chained method calls, manual parsing of request data, and repetitive configuration, which can make tests harder to read and maintain.

WireMock.Net.Routing addresses these pain points by introducing a concise, fluent, and minimal-API-inspired approach to routing. This makes your test code:

  • More readable: Route definitions are clear and expressive, closely resembling production minimal APIs.
  • Easier to maintain: Less boilerplate means fewer places for errors and easier refactoring.
  • Faster to write: Define routes and handlers in a single line, with strong typing and async support.

Example: Native WireMock.Net vs. WireMock.Net.Routing

Native WireMock.Net
server.Given(
    Request.Create().WithPath("/hello").UsingGet()
)
.RespondWith(
    Response.Create().WithBody("Hello, world!")
);

server.Given(
    Request.Create().WithPath("/user/*").UsingGet()
)
.RespondWith(
    Response.Create().WithCallback(request =>
    {
        var id = request.PathSegments[1];
        // ...fetch user by id...
        return new ResponseMessage { Body = $"User: {id}" };
    })
);
With WireMock.Net.Routing
router.MapGet("/hello", _ => "Hello, world!");

router.MapGet("/user/{id:int}", requestInfo =>
{
    var id = requestInfo.RouteArgs["id"];
    // ...fetch user by id...
    return $"User: {id}";
});

With WireMock.Net.Routing, you get:

  • Minimal, one-line route definitions
  • Typed route parameters (e.g., {id:int})
  • Direct access to parsed route arguments and request bodies
  • Async handler support

This leads to more maintainable, scalable, and production-like test code.


Features

  • Minimal API-style route definitions for WireMock.Net
  • Strongly-typed request handling
  • Routing parameters with constraints (int and string are currently supported)
  • Asynchronous handlers
  • Fluent, composable routing extensions
  • Easy integration with existing WireMock.Net servers
  • .NET 8+ support

Installation

Install from NuGet:

dotnet add package WireMock.Net.Routing

Quick Start

using System.Net.Http.Json;
using WireMock.Net.Routing;
using WireMock.Net.Routing.Extensions;
using WireMock.Server;

var server = WireMockServer.Start();
var router = new WireMockRouter(server);

router.MapGet("/hello", _ => "Hello, world!");

using var client = server.CreateClient();
var result = await client.GetFromJsonAsync<string>("/hello");
// Hello, world!

Usage

Routing with route parameters

router.MapGet("/user/{id:int}", async requestInfo => {
    var userId = requestInfo.RouteArgs["id"];
    // var user = await ...
    return user;
});

Strongly-Typed Request Info

router.MapPost<Item>("/api/items", requestInfo => {
    var item = requestInfo.Body!;
    // process item
    return Results.Json(new { success = true });
});

Supported Methods

  • MapGet, MapPost, MapPut, MapDelete

Documentation


Contributing

Contributions are welcome! Please open issues or pull requests. See CONTRIBUTING.md if available.


License

This project is licensed under the MIT License. See LICENSE for details.


Support & Feedback

For questions, suggestions, or issues, please use the GitHub Issues page.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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 is compatible.  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. 
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
1.0.1 209 7/26/2025
1.0.0 209 7/26/2025