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.

Inheritance

Constructors

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

Properties

basePath String
A prefix for all routes on this instance.
no setter
hashCode int
The hash code for this object.
no setterinherited
logger Logger
An instance of the 'liquidart' logger.
no setterinherited
nextController Controller?
Receives requests that this controller does not respond to.
no setterinherited
policy CORSPolicy?
The CORS policy of this controller.
getter/setter pairinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

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

Operators

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