Router class

Core HTTP router with support for:

  • Static and dynamic routes
  • Parameterized routes with type coercion (/users/{id:int}
  • Nested route groups with shared middleware/prefixes
  • Middleware pipelines
  • Zone-based parameter injection

Dynamic Route Syntax:

router.get('/users/{id:int}/posts/{slug:string}', handler);

Supported Parameter Types: int, double, uuid, string

Constructors

Router()

Properties

hashCode int
The hash code for this object.
no setterinherited
routes Map<HttpMethod, Map<String, Handler>>
Public view of registered static routes (for debugging).
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

addRoute(Route r) → void
Registers a pre-defined Route object.
delete(String path, Handler handler, {List<HttpMiddleware> middleware = const []}) → void
Registers a DELETE route.
dispatch(HttpRequest request) → void
Dispatches an HttpRequest to the matching route.
get(String path, Handler handler, {List<HttpMiddleware> middleware = const []}) → void
Registers a GET route.
group({String prefix = '', List<HttpMiddleware> middleware = const [], required void routes()}) → void
Defines a route group with shared prefix and middleware.
listRoutes() Map<HttpMethod, List<String>>
Lists all registered routes (static paths + dynamic regex patterns).
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
patch(String path, Handler handler, {List<HttpMiddleware> middleware = const []}) → void
Registers a PATCH route.
post(String path, Handler handler, {List<HttpMiddleware> middleware = const []}) → void
Registers a POST route.
put(String path, Handler handler, {List<HttpMiddleware> middleware = const []}) → void
Registers a PUT route.
toString() String
A string representation of this object.
inherited

Operators

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