Phema.Routing 3.0.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package Phema.Routing --version 3.0.3                
NuGet\Install-Package Phema.Routing -Version 3.0.3                
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="Phema.Routing" Version="3.0.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Phema.Routing --version 3.0.3                
#r "nuget: Phema.Routing, 3.0.3"                
#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.
// Install Phema.Routing as a Cake Addin
#addin nuget:?package=Phema.Routing&version=3.0.3

// Install Phema.Routing as a Cake Tool
#tool nuget:?package=Phema.Routing&version=3.0.3                

Phema.Routing

Build Status Nuget

C# strongly typed routing library for ASP.NET Core built on top of MVC Model conventions with built-in From.*, ApiExplorer, Authorization and Caching support

Features

  • Flexible constraint and filter configuration
  • Extension methods for authorization, caching, api documentation
  • Selection BindingSources and named parameters (constant names only) e.g. From.Body, From.Form, From.Route etc.
  • Parameter name override e.g. From.Query<int>("id_override") /route?id_override=12345
  • Extensions
    • Http methods - .HttpPost()...
    • Caching - .Cached(...)
    • Authorization - .Authorize(...), .AllowAnonymous()
    • AntiForgeryToken - .ValidateAntiForgeryToken(), .IgnoreAntiforgeryToken()
    • Https - .RequireHttps()
    • RequestSizeLimit - .RequestSizeLimit(...), .DisableRequestSizeLimit()
    • Produce, Consume for ApiExplorer - .Produces<TModel>(...), .Consumes(...)

Usage

// Startup
services.AddControllers() // `.AddMvc()`, `.AddMvcCore()`
  .AddRouting(routing =>
  {
    // Simple route
    routing.AddController<OrdersController>("orders", controller =>
      controller.AddRoute("dashboard", c => c.Dashboard())
        .HttpGet());

    // Authorize controller with "id" parameter from query
    routing.AddController<TaskController>("tasks", controller =>
      controller.AddRoute("edit/{id}", c => c.Edit(From.Route<int>("id"))) // `From.*` is matches `[From*]` attributes
        .HttpGet()
        .Authorize());

    // Multiple routes in one controller
    routing.AddController<WashingController>("washing", controller =>
    {
      // Override controller `.Authorize()`
      controller.AddRoute("wash", c => c.Wash(From.Query<int>())) // If name not specified - used method parameter name
        .HttpGet()
        .AllowAnonymous()

      // Inherit authorization requirement from controller
      controller.AddRoute("dry", c => c.Dry(From.Body<DryModel>()))
        .HttpPost()
        .ValidateAntiForgeryToken();
    }).Authorize();

    // Multiple binding sources
    routing.AddController<MoviesController>("movies", controller =>
      controller.AddRoute("{category}/upload", c =>
        c.Upload(From.Route<string>(), From.Body<UploadMovieModel>(), From.Query<bool>("compress")))
        .HttpPost());
  });

Action url generation (IUrlHelper used)

// From.Query with parameter override
services.AddRouting(routing =>
  routing.AddController<Controller>("controller", controller =>
    controller.AddRoute("action", c => c.Action(From.Query<int>("parameter")))));

// "controller/action?parameter=10"
var action = Url.Action<Controller>(c => c.Action(10));

// From.Route with route part override
services.AddRouting(routing =>
  routing.AddController<Controller>("controller", controller =>
    controller.AddRoute("action/{mode}", c => c.Route(From.Route<Mode>("mode")))));

// "controller/action/access"
var action = Url.Action<Controller>(c => c.Action("access"));

// Combine query and route parts
services.AddRouting(routing =>
  routing.AddController<Controller>("controller", controller =>
    controller.AddRoute("action/{mode}", c => c.Route(From.Query<int>(), From.Route<Mode>()))));

// "controller/action/access?parameter=10"
var action = Url.Action<Controller>(c => c.Action(10, "access"));

// Get values from current request using From.Query in IUrlHelper generation
services.AddRouting(routing =>
  routing.AddController<Controller>("controller", controller =>
    controller.AddRoute("action", c => c.Action(From.Query<int>()))));

// P.S. BindingSources not used in url will ignored (e.g. `From.Body<TModel>()` used only for compile reasons)
// "controller/action?parameter=VALUE_FROM_CURRENT_REQUEST"
var action = Url.Action<Controller>(c => c.Action(From.Query<int>()));
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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
3.0.5 1,205 9/25/2019
3.0.4 1,051 8/27/2019
3.0.3 1,238 7/27/2019
3.0.2 1,178 7/26/2019
3.0.1 1,166 7/25/2019
3.0.0 1,024 7/19/2019