Router class

Constructors

Router({Pipeline notFoundPipeline, Handler notFoundHandler, Pipeline serverErrorPipeline, Handler serverErrorHandler})
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. [...]
read-only, inherited
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited

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.
clearMiddleware() → 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) → 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 non-existent method or property is accessed. [...]
inherited
notFound(Handler handler) → Route
Add a custom handler to execute when a route is not found. By default, the router simply returns a 404 error.
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
recover([Recoverer recover]) → void
Add a Recoverer function to execute when an unhandled exception or error occurs. If added but a custom Recoverer is not provided, the default Recover prints the Exception/Error message and stack trace.
serve(Request req) Future<Response>
toString() String
Returns a string representation of this object.
inherited
use(Middleware middleware) → void
Add a Middleware to this Router's middleware stack.

Operators

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