Router class

Determines which Controller should receive a Request based on its path.

A router is a Controller that evaluates the path of a Request and determines which controller should be the next to receive it. Valid paths for a Router are called routes and are added to a Router via route.

Each route creates a new Controller that will receive all requests whose path match the route pattern. If a request path does not match one of the registered routes, Router responds with 404 Not Found and does not pass the request to another controller.

Unlike most Controllers, a Router may have multiple controllers it sends requests to. In most applications, a Router is the ApplicationChannel.entryPoint.



Router({String basePath, Future notFoundHandler(Request request) })
Creates a new Router.


basePath → String
A prefix for all routes on this instance. [...]
hashCode → int
The hash code for this object.
read-only, inherited
logger Logger
An instance of the 'aqueduct' logger.
read-only, inherited
nextController Controller
Receives requests that this controller does not respond to. [...]
read-only, inherited
policy CORSPolicy
The CORS policy of this controller.
read / write, inherited
runtimeType → Type
A representation of the runtime type of the object.
read-only, inherited


didAddToChannel() → void
Lifecycle callback, invoked after added to channel, but before any requests are served. [...]
documentComponents(APIDocumentContext context) → void
Tells this object to add its components to context. [...]
documentPaths(APIDocumentContext context) → Map<String, APIPath>
Tells this object to return all APIPaths it handles. [...]
handle(Request request) → FutureOr<RequestOrResponse>
The primary request handling method of this object. [...]
Routers override this method to throw an exception. Use route instead.
linkFunction(FutureOr<RequestOrResponse> handle(Request request)) Linkable
Links a function controller to the receiver to form a request channel. [...]
receive(Request req) → Future
Delivers req to this instance to be processed. [...]
route(String pattern) Linkable
Adds a route that Controllers can be linked to. [...]
toString() → String
Returns a string representation of this object.
applyCORSHeadersIfNecessary(Request req, Response resp) → void
documentOperations(APIDocumentContext context, String route, APIPath path) → Map<String, APIOperation>
Tells this object to return all APIOperations it handles. [...]
handleError(Request request, dynamic caughtValue, StackTrace trace) → Future
Sends an HTTP response for a request that yields an exception or error. [...]
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed.
willSendResponse(Response response) → void
Executed prior to Response being sent. [...]


operator ==(dynamic other) → bool
The equality operator.