Sisk

Class

Router

Namespace
Sisk.Core.Routing
Assembly
Sisk.Core.dll

Represents a collection of Route and main executor of actions in the HttpServer.

C#
public sealed class Router : IReadOnlyCollection<Route>, IEnumerable<Route>, IEnumerable

Inheritance #

object ← Router

Implements #

IReadOnlyCollection<Route>, IEnumerable<Route>, IEnumerable

Inherited Members #

object.GetType(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

Constructors #

NameDescription
Router()Creates an new Router instance with default values.
Router(params IEnumerable<Route>)Creates an new Router instance with given route collection.

Properties #

NameDescription
CallbackErrorHandlerGets or sets the Router action exception handler. The response handler for this property will send an HTTP response to the client when an exception is caught during execution. This property is only called when ThrowExceptions is disabled.
CheckForRouteCollisionsGets or sets whether this Router should check for possible routing collisions before starting the HTTP server.
Count
GlobalRequestHandlersGets or sets the global requests handlers that will be executed in all matched routes.
IsReadOnlyGets an boolean indicating where this Router is read-only or not.
MatchRoutesIgnoreCaseGets or sets whether this Router will match routes ignoring case.
MethodNotAllowedErrorHandlerGets or sets the Router “405 Method Not Allowed” handler.
NotFoundErrorHandlerGets or sets the Router “404 Not Found” handler.
PrefixGets or sets the prefix which will be applied to all next defining routes in this router.

Methods #

NameDescription
AutoScanModules(Type, Assembly)Scans for all types that implements the specified module type and associates an instance of each type to the router.
AutoScanModules<TModule>(Assembly)Scans for all types that implements TModule and associates an instance of each type to the router. Note that, TModule must be an RouterModule type and an accessible constructor for each type must be present.
AutoScanModules<TModule>()Scans for all types that implements TModule and associates an instance of each type to the router. Note that, TModule must be an RouterModule type and an accessible constructor for each type must be present.
Combine(params string[])Combines an array of string parts into a single path.
GetDefinedRoutes()Gets all routes defined on this router instance.
GetEnumerator()
GetRouteFromName(string)Gets an defined Route by their name property.
GetRouteFromPath(RouteMethod, string)Gets the first matched Route by their HTTP method and path.
GetRouteFromPath(string)Gets the first matched Route by their URL path.
GetRouteMethod(HttpMethod, RouteMethod)Gets the corresponding RouteMethod for a given HttpMethod, with a fallback option.
GetRouteMethod(string, RouteMethod)Gets the corresponding RouteMethod for a given HTTP method string, with a fallback option.
IsDefined(RouteMethod, string)Gets an boolean indicating if there are any route that matches the specified method and route path.
IsRouteExpressionsOverlap(in ReadOnlySpan<char>, in ReadOnlySpan<char>, StringComparison)Determines whether two route expressions overlap.
IsRouteExpressionsOverlap(string, string, StringComparison)Determines whether two route expressions overlap.
Map(Route)Maps a route into this router.
Map(IEnumerable<Route>)Maps a collection of routes into this router.
Map(RouteMethod, string, Delegate?)Maps a route using the specified method, path and action.
Map(RouteMethod, string, Delegate?, IRequestHandler[]?)Maps a route using the specified method, path, action and request handlers.
MapAny(string, Delegate)Maps an route which matches any HTTP method, using the specified path and action function.
MapAny(string, RouteAction)Maps an route which matches any HTTP method, using the specified path and action function.
MapDelete(string, Delegate)Maps an DELETE route using the specified path and action function.
MapDelete(string, RouteAction)Maps an DELETE route using the specified path and action function.
MapFileSystem(string, string)Maps a file system route.
MapFileSystem(string, HttpFileServerHandler, IRequestHandler[]?)Maps a file system route using a custom handler.
MapGet(string, Delegate)Maps an GET route using the specified path and action function.
MapGet(string, RouteAction)Maps an GET route using the specified path and action function.
MapHead(string, Delegate)Maps an HEAD route using the specified path and action function.
MapHead(string, RouteAction)Maps an HEAD route using the specified path and action function.
MapInstance(object)Maps route methods from an object instance.
MapInstance<TInstance>()Maps route methods from a new instance of TInstance.
MapOptions(string, Delegate)Maps an OPTIONS route using the specified path and action function.
MapOptions(string, RouteAction)Maps an OPTIONS route using the specified path and action function.
MapPatch(string, Delegate)Maps an PATCH route using the specified path and action function.
MapPatch(string, RouteAction)Maps an PATCH route using the specified path and action function.
MapPost(string, Delegate)Maps an POST route using the specified path and action function.
MapPost(string, RouteAction)Maps an POST route using the specified path and action function.
MapPut(string, Delegate)Maps an PUT route using the specified path and action function.
MapPut(string, RouteAction)Maps an PUT route using the specified path and action function.
MapQuery(string, Delegate)Maps an QUERY route using the specified path and action function.
MapQuery(string, RouteAction)Maps an QUERY route using the specified path and action function.
MapType<T>()Maps static route methods from T.
MapType(Type)Maps static route methods from a type.
MatchRouteExpression(in ReadOnlySpan<char>, in ReadOnlySpan<char>, StringComparison)Attempts to match the specified route expression against the given path.
MatchRouteExpression(string, string, StringComparison)Attempts to match the specified route expression against the given path.
RegisterValueHandler<T>(RouterActionHandlerCallback<T>)Register an type handling association to converting it to an HttpResponse object.
ResolveActionResult(object?)Resolves the specified object into an valid HttpResponse using the defined value handlers or throws an exception if not possible.
Rewrite(string, string)Maps a rewrite route, which redirects all requests that match the given path to another path, keeping the body and headers of the original request.
SetObject(object)Searches for all instance and static methods that are marked with an attribute of type RouteAttribute in the specified object and creates routes for these methods.
SetObject(Type)Searches for all instance and static methods that are marked with an attribute of type RouteAttribute in the specified object and creates routes for these methods.
SetObject(Type, object)Searches for all instance and static methods that are marked with an attribute of type RouteAttribute in the specified object and creates routes for these methods.
SetObject<TObject>()Searches for all instance and static methods that are marked with an attribute of type RouteAttribute in the specified object and creates routes for these methods.
SetObject<TObject>(TObject)Searches for all instance and static methods that are marked with an attribute of type RouteAttribute in the specified object and creates routes for these methods.
SetRoute(RouteMethod, string, RouteAction)Defines an route with their method, path and action function.
SetRoute(RouteMethod, string, Delegate)Defines an route with their method, path and action function.
SetRoute(RouteMethod, string, Delegate, string?)Defines an route with their method, path, action function and name.
SetRoute(RouteMethod, string, Delegate, string?, IRequestHandler[])Defines an route with their method, path, action function, name and request handlers.
SetRoute(Route)Defines an route in this Router instance.
SetRoutes(params IEnumerable<Route>)Defines the specified collection of routes.
TryResolveActionResult(object?, out HttpResponse?)Tries to resolve the specified object into an valid HttpResponse using the defined value handlers.

Type to search the documentation and the API reference.