Router class

Manages routing logic with support for HTTP methods and middleware.

This class orchestrates modular components for better maintainability and separation of concerns.

Constructors

Router()

Properties

hashCode int
The hash code for this object.
no setterinherited
routes List<Route>
Returns the list of registered routes.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

any(String path, RequestHandler handler, {List<Middleware> middleware = const []}) → void
Registers a route for any method.
clear() → void
Clears all registered routes.
delete(String path, RequestHandler handler, {List<Middleware> middleware = const [], String? name}) → void
Registers a DELETE route.
get(String path, RequestHandler handler, {List<Middleware> middleware = const [], String? name}) → void
Registers a GET route.
group({required String prefix, required void routes(Router), List<Middleware> middleware = const []}) → void
Groups a set of routes under a prefix and optional middleware.
Registers a HEAD route.
match(String method, String path) RouteMatchResult?
Matches a route for the given method and path. Matches the first route that fits the given method and path.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
options(String path, RequestHandler handler, {List<Middleware> middleware = const [], String? name}) → void
Registers an OPTIONS route.
patch(String path, RequestHandler handler, {List<Middleware> middleware = const [], String? name}) → void
Registers a PATCH route.
post(String path, RequestHandler handler, {List<Middleware> middleware = const [], String? name}) → void
Registers a POST route.
put(String path, RequestHandler handler, {List<Middleware> middleware = const [], String? name}) → void
Registers a PUT route.
register(String method, String path, RequestHandler handler, List<Middleware> middleware, {String? name}) → void
Registers a route with the specified method, path, handler, and optional middleware.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited