Naravel.Routing
0.2.0
dotnet add package Naravel.Routing --version 0.2.0
NuGet\Install-Package Naravel.Routing -Version 0.2.0
<PackageReference Include="Naravel.Routing" Version="0.2.0" />
<PackageVersion Include="Naravel.Routing" Version="0.2.0" />
<PackageReference Include="Naravel.Routing" />
paket add Naravel.Routing --version 0.2.0
#r "nuget: Naravel.Routing, 0.2.0"
#:package Naravel.Routing@0.2.0
#addin nuget:?package=Naravel.Routing&version=0.2.0
#tool nuget:?package=Naravel.Routing&version=0.2.0
Naravel.Routing
Laravel-style routing and middleware for ASP.NET Core: fluent route groups, named routes, route model binding, resource routes and a middleware engine with aliases, groups, parameters, priority, withoutMiddleware and terminable middleware.
| Fact | Detail |
|---|---|
| Install | dotnet add package Naravel.Routing |
| Targets | .NET 10 |
| Needs | ASP.NET Core (the Microsoft.AspNetCore.App shared framework) and no other Naravel package |
| Add-on | Naravel.Routing.Cache shares the throttle quota between application instances |
What you get
- Fluent routes on Minimal APIs. Groups (
Prefix,Name,Domain,Middleware), named routes with a URL generator,Whereconstraints, resource routes and route model binding. - Mistakes fail at startup. Nothing is mapped until the
MapNaravelcallback returns, so the order ofName,WhereandMiddlewaredoes not matter, and aWherefor a parameter that is not in the URI throws when the application starts. - Ready-made middleware.
throttle,signed,maintenance,cache.headers,trim,convert.emptyandguest; your ownIRouteMiddlewareclasses register under an alias. - A throttle that scales out. It counts in the process by default, and
Naravel.Routing.Cachemakes every instance share one count. - Easy to test. A route middleware is a plain class you can call without a host, and
TestServerruns the real pipeline in memory.
Quick start
using Naravel.Routing;
builder.Services.AddNaravelRouting(o =>
{
o.Middleware.Alias<EnsureTenant>("tenant"); // EnsureTenant is your own route middleware, shown below
o.ConfigureThrottlePolicy("login", 5, TimeSpan.FromMinutes(1));
});
app.UseNaravelRouting(); // runs the route middleware; if you call UseRouting() yourself, call this after it
app.MapNaravel(r =>
{
r.Get("/", () => "home").Name("home");
r.Post("/login", () => Results.Ok()).Middleware("throttle:login");
r.Prefix("api").Middleware("tenant").Group(api =>
{
api.Get("orders/{id}", (int id) => Results.Ok(id)).Where("id", "[0-9]+").Name("orders.show");
});
});
public sealed class EnsureTenant : IRouteMiddleware
{
public async Task InvokeAsync(HttpContext context, RequestDelegate next, MiddlewareArguments arguments)
{
if (!context.Request.Headers.ContainsKey("X-Tenant"))
{
context.Response.StatusCode = StatusCodes.Status400BadRequest; // short-circuit
return;
}
await next(context);
}
}
There is no built-in auth middleware, so register your own with o.Middleware.Alias.
throttle counts attempts in the process by default, so with several instances each one has its own count. To share one count, add the Naravel.Routing.Cache package and call services.AddNaravelSharedThrottle("shared"), where "shared" is the name of a Naravel.Cache store that every instance uses (a Redis or Memcached store; a Memory store is still per process). The routing guide shows the full setup. A request over the limit gets a 429 response.
Related packages
| Package | Adds |
|---|---|
Naravel.Routing.Cache |
A throttle store that every application instance shares, counting in a Naravel.Cache store such as Redis |
Learn more
- Routing: English guide
- Changelog · Source and issues · MIT license
Part of Naravel: Laravel's names, .NET's type system. All Naravel packages share one version.
| 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 (1)
Showing the top 1 NuGet packages that depend on Naravel.Routing:
| Package | Downloads |
|---|---|
|
Naravel.Routing.Cache
A shared store for the Naravel.Routing throttle middleware, counting in a Naravel.Cache store (for example Redis) so every application instance uses one quota. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Release notes: https://github.com/km-arc/Naravel/releases/tag/v0.2.0 - full history: https://github.com/km-arc/Naravel/blob/main/CHANGELOG.md