Class Router

Executes the route matching pipeline built by RouteBuilder.

Inheritance
object
RoutingContext
Router
HttpListenerRouter
Inherited Members
object.GetType()
object.MemberwiseClone()
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
Namespace: NanoRoute
Assembly: NanoRoute.dll
Syntax
public abstract class Router : RoutingContext
Remarks

A router is created from a builder snapshot. Matching walks the configured route tree, attaches bound parameters, and invokes compatible handlers in order until one returns a response without delegating further.

Constructors

Router(RouteBuilder, RouterConfig)

Executes the route matching pipeline built by RouteBuilder.

Declaration
protected Router(RouteBuilder routeBuilder, RouterConfig config)
Parameters
Type Name Description
RouteBuilder routeBuilder
RouterConfig config
Remarks

A router is created from a builder snapshot. Matching walks the configured route tree, attaches bound parameters, and invokes compatible handlers in order until one returns a response without delegating further.

Fields

OriginalRequestName

The request property key that stores the original transport-specific request object.

Declaration
public const string OriginalRequestName = "OriginalRequest"
Field Value
Type Description
string

TraceIdName

The request property key that stores the trace identifier associated with the current request.

Declaration
public const string TraceIdName = "TraceId"
Field Value
Type Description
string

Properties

Config

Configuration assigned to this instance.

Declaration
public RouterConfig Config { get; }
Property Value
Type Description
RouterConfig

Methods

Handle(HttpRequestMessage, IServiceProvider, CancellationToken)

Routes an HttpRequestMessage through the configured handler pipeline.

Declaration
protected Task<HttpResponseMessage> Handle(HttpRequestMessage request, IServiceProvider services, CancellationToken cancellation = default)
Parameters
Type Name Description
HttpRequestMessage request

The request to process.

IServiceProvider services

The service provider exposed to value parsers and handlers.

CancellationToken cancellation

A token that can cancel request processing.

Returns
Type Description
Task<HttpResponseMessage>

The HttpResponseMessage produced by the matching handlers.

Remarks

Prefix routes can participate in the same pipeline as exact routes. Consecutive / separators in the request path are treated as a single separator during matching. When several handlers match, NanoRoute evaluates compatible matches from shorter prefixes toward more specific matches and honors MatchingPrecedence when both literal and parameterized segments are available at the same depth. Once a branch is selected at a given depth, NanoRoute does not return to sibling branches later in the pipeline.

Exceptions
Type Condition
HttpRequestException

Thrown when no handler matches the request path.

ArgumentException

Thrown when the request uses an unsupported HTTP method.

OperationCanceledException

Thrown when the caller cancels the cancellation.

In this article
Back to top Generated by DocFX