Router class Null safety

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)?})
Creates a new Router.

Properties

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

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 non-existent 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