Rerout.AspNetCore
0.3.0
dotnet add package Rerout.AspNetCore --version 0.3.0
NuGet\Install-Package Rerout.AspNetCore -Version 0.3.0
<PackageReference Include="Rerout.AspNetCore" Version="0.3.0" />
<PackageVersion Include="Rerout.AspNetCore" Version="0.3.0" />
<PackageReference Include="Rerout.AspNetCore" />
paket add Rerout.AspNetCore --version 0.3.0
#r "nuget: Rerout.AspNetCore, 0.3.0"
#:package Rerout.AspNetCore@0.3.0
#addin nuget:?package=Rerout.AspNetCore&version=0.3.0
#tool nuget:?package=Rerout.AspNetCore&version=0.3.0
Rerout.AspNetCore
ASP.NET Core integration for the Rerout branded-link SDK.
Registers the Rerout client in dependency injection and adds a signature-verified webhook endpoint — verify, deserialize, dispatch, in one line of routing.
Install
dotnet add package Rerout.AspNetCore
Targets net8.0 and the ASP.NET Core shared framework. Pulls in the base
Rerout package.
Register the client
using Rerout.AspNetCore.DependencyInjection;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddRerout(builder.Configuration["Rerout:ApiKey"]!);
AddRerout registers a singleton ReroutClient. Inject it anywhere:
app.MapGet("/links", async (ReroutClient rerout) =>
{
var page = await rerout.Links.ListAsync(limit: 50);
return page.Links;
});
Pass ReroutClientOptions for a custom base URL, timeout, or HttpClient:
builder.Services.AddRerout(
builder.Configuration["Rerout:ApiKey"]!,
new ReroutClientOptions { Timeout = TimeSpan.FromSeconds(10) });
Receive webhooks
Configure the signing secret, register a handler, and map the endpoint:
using Rerout.AspNetCore;
using Rerout.AspNetCore.DependencyInjection;
builder.Services
.AddRerout(builder.Configuration["Rerout:ApiKey"]!)
.AddReroutWebhooks(builder.Configuration["Rerout:WebhookSecret"]!)
.AddReroutWebhookHandler<ReroutEventHandler>();
var app = builder.Build();
app.MapReroutWebhook("/webhooks/rerout");
app.Run();
MapReroutWebhook maps a POST endpoint that:
- reads the raw request body,
- verifies the
X-Rerout-Signatureheader (HMAC-SHA256, constant-time), - deserializes the event,
- calls your
IReroutEventHandler, - and returns the right status code.
| Outcome | Status |
|---|---|
| Verified, parsed, handled | 200 OK |
| Missing or invalid signature | 401 Unauthorized |
| Body absent or not a valid event | 400 Bad Request |
| No handler registered / handler throws | 500 |
Handle events
using Rerout.AspNetCore;
using Rerout.AspNetCore.Events;
public sealed class ReroutEventHandler : IReroutEventHandler
{
private readonly ILogger<ReroutEventHandler> _logger;
public ReroutEventHandler(ILogger<ReroutEventHandler> logger) => _logger = logger;
public Task HandleAsync(ReroutWebhookEvent webhookEvent, CancellationToken ct)
{
switch (webhookEvent.Type)
{
case "link.clicked":
var click = webhookEvent.GetData<LinkClicked>();
_logger.LogInformation("Click on {Code} from {Country}", click.Code, click.Country);
break;
case "qr.scanned":
var scan = webhookEvent.GetData<QrScanned>();
_logger.LogInformation("QR scan of {Code}", scan.Code);
break;
case "domain.failed":
var failure = webhookEvent.GetData<DomainFailed>();
_logger.LogWarning("Domain {Host} failed: {Reason}", failure.Hostname, failure.Reason);
break;
}
return Task.CompletedTask;
}
}
The handler is registered as scoped, so it may depend on scoped services
such as a DbContext. The middleware only invokes it after the signature has
been verified — the event is guaranteed authentic.
ReroutWebhookEvent exposes Type, Id, and CreatedAt, plus Data as a
JsonElement and a typed GetData<T>() for the records in
Rerout.AspNetCore.Events: LinkClicked, QrScanned, DomainFailed.
Tolerance
AddReroutWebhooks defaults to a 5-minute timestamp tolerance. Override it:
.AddReroutWebhooks(options =>
{
options.SigningSecret = builder.Configuration["Rerout:WebhookSecret"]!;
options.ToleranceSeconds = 0; // disable the replay-protection check
})
Error handling
ReroutClient calls throw ReroutException on failure — see the base
Rerout package for Code, Status,
and the IsRateLimited / IsServerError flags.
Local development
dotnet restore
dotnet build
dotnet test
dotnet format --verify-no-changes
The package references the base Rerout SDK by ProjectReference for local
development; published builds use a versioned PackageReference.
License
MIT — see LICENSE. Part of the Rerout SDK workspace: https://github.com/ModestNerds-Co/rerout-sdks.
| Product | Versions 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. |
-
net8.0
- Rerout (>= 0.3.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.