Router class

Constructors

Router({Pipeline? notFoundPipeline, bool shouldRecover = true, Recoverer? recoverer})
A Router is created to specify the URIs (routes) that the server can handle. Routers take middleware, which are functions that are executed on Requests (RequestMiddleware) and Responsees (ResponseMiddleware). Routers also take a Handler, which is the function to execute for the specified route. Middleware are executed in the following order:

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

canHandle(Uri uri) bool
Returns true if the router base route matches part of the requested URI. This is used when matching route groups to URIs.
clearPipeline() → void
Removes all the Middleware from the stack. Useful for clearing and then redefining the middleware for a router group.
delete(String pattern, Handler endpoint) → Route
Create a DELETE route with the specified URI pattern and handler
get(String pattern, Handler endpoint, {Pipeline? pipeline}) → Route
Create a GET route with the specified URI pattern and handler
group(String pattern) Router
Create a new Router Group (sub-router) that shares part of a URI with its child routes. By default the new group inherits the Middleware stack from its parent but the Middleware stack can have Middleware added or completely cleared.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onRequest(RequestMiddleware requestMiddleware, {bool runAsync = false, bool useAlways = false}) → void
Add a RequestMiddleware to this router's middleware stack
onResponse(ResponseMiddleware responseMiddleware, {bool runAsync = false, bool useAlways = false}) → void
Add a ResponseMiddleware to this router's middleware stack
pipeline(Pipeline pipeline) → void
post(String pattern, Handler endpoint) → Route
Create a POST route with the specified URI pattern and handler
printRoutes() → void
A convenience method that will print all of the routes that this Router will handle when the router is initialized.
put(String pattern, Handler endpoint) → Route
Create a PUT route with the specified URI pattern and handler
serve(Request req) Future<Response?>
toString() String
A string representation of this object.
inherited

Operators

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

Static Methods

createPipeline() → Pipeline