JG.WebKit.Router 1.0.1

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

JG.WebKit.Router

NuGet Downloads License CI


A high-performance trie-based HTTP router for ASP.NET Core. Built for speed with O(1) route matching, compiled per-route execution chains, and zero-allocation path parsing.

Part of the JG WebKit collection.

Features

  • Trie-based matching — O(1) average route lookups using an immutable trie data structure
  • Compiled execution chains — routes execute pre-compiled handler chains, not middleware pipelines
  • Hot-reload — add, modify, or remove routes at runtime without restarting
  • Route groups — organize routes with shared prefixes and chain nodes
  • 11 built-in constraintsint, long, guid, bool, slug, alpha, alphanum, filename, range(min,max), length(min,max), regex(pattern)
  • Custom constraints — implement IRouteConstraint for custom validation
  • Dynamic routes — load routes from any source via IRouteProvider
  • Route metadata — attach custom metadata to routes
  • Zero-allocation path parsing — uses ReadOnlySpan<char> for minimal GC pressure
  • Thread-safe — lock-free hot path with atomic trie swap on reload
  • Fluent API — chainable route registration with MapRoute() and MapRouteGroup()

Installation

dotnet add package JG.WebKit.Router

Quick Start

Basic Routing

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddWebKitRouter();

var app = builder.Build();
app.UseWebKitRouter();

// Simple route
app.MapRoute("GET", "/", (ctx, ct) => 
    ValueTask.FromResult(RouteResult.Ok("Hello, World!")));

// Route with parameter
app.MapRoute("GET", "/users/{id:int}", (ctx, ct) =>
{
    var userId = ctx.Match.Parameters["id"];
    return ValueTask.FromResult(RouteResult.Json(new { userId }));
});

app.Run();

Route Groups

app.MapRouteGroup("/api/v1", group =>
{
    group.MapRoute("GET", "/users", ListUsers);
    group.MapRoute("GET", "/users/{id:int}", GetUser);
    group.MapRoute("POST", "/users", CreateUser);
});

Execution Chains

Chain nodes execute before the route handler and can short-circuit:

public class AuthChainNode : IChainNode
{
    public async ValueTask<ChainResult> ExecuteAsync(RequestContext context, CancellationToken ct)
    {
        if (!context.HttpContext.User.Identity?.IsAuthenticated ?? false)
            return ChainResult.Stop(RouteResult.Unauthorized());
        return ChainResult.Next();
    }
}

app.MapRoute("GET", "/secure", SecureHandler)
    .AddChainNode(new AuthChainNode());

Documentation

Performance

  • Route matching: O(1) average lookup via trie dictionary
  • Path parsing: Zero allocations using ReadOnlySpan<char>
  • Request handling: No locks on hot path (volatile reads only)
  • Regex constraints: Compiled and cached at build time

License

Licensed under the Apache License 2.0. See LICENSE for details.


Get started: Install from NuGet, then check out the API documentation.

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.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.

Version Downloads Last Updated
1.0.1 87 3/6/2026