Router class

A router to split requests based on their URI path.

Instances of this class maintain a collection of RouteControllers for each route that has been registered with it. Routes are registered through the route method. RouteControllers are subclasses of RequestController so that further RequestControllers can be chained off of it. When a Request is delivered to the router, it will pass it on to the associated RouteController or respond to the Request with a 404 status code.

A route is defined by a String format, for example: router.route("/users"); router.route("/posts/:id"); router.route("/things/:id"); router.route("/numbers/:id(\d+)"); router.route("/files/*");

Inheritance

Constructors

Router()
Creates a new Router.

Properties

basePath String
A string to be prepended to the beginning of every route this Router manages. [...]
read / write
unhandledRequestController Future Function(Request)
How this router handles Requests that don't match its routes. [...]
write-only
documentableChild APIDocumentable
Returns the next documentable object in a chain of documentable objects. [...]
read-only, inherited
hashCode int
The hash code for this object. [...]
read-only, inherited
logger Logger
An instance of the 'aqueduct' logger.
read-only, inherited
nextController RequestController
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

Methods

documentPaths(PackagePathResolver resolver) List<APIPath>
Returns all APIPath objects this instance knows about. [...]
finalize() → void
Invoke on this router once all routes are added. [...]
generate(RequestController generatorFunction()) RequestController
Routers override this method to throw an exception. Use route instead.
listen(FutureOr<RequestOrResponse> requestControllerFunction(Request request)) RequestController
Routers override this method to throw an exception. Use route instead.
pipe(RequestController n) RequestController
Routers override this method to throw an exception. Use route instead.
receive(Request req) Future
Delivers req to this instance to be processed. [...]
route(String pattern) RequestController
Adds a route to this instnace and provides a forwarding RouteController for all Requests that match that route to be delivered on. [...]
applyCORSHeadersIfNecessary(Request req, Response resp) → void
inherited
documentAPI(PackagePathResolver resolver) APIDocument
Returns an entire APIDocument describing an OpenAPI specification. [...]
inherited
documentOperations(PackagePathResolver resolver) List<APIOperation>
Returns all APIOperations this object knows about.
inherited
documentRequestBodyForOperation(APIOperation operation) APIRequestBody
Returns all APIRequestBodys for operation.
inherited
documentResponsesForOperation(APIOperation operation) List<APIResponse>
Returns all APIResponses for operation.
inherited
documentSecuritySchemes(PackagePathResolver resolver) Map<String, APISecurityScheme>
Returns all APISecuritySchemes this instance knows about.
inherited
handleError(Request request, dynamic caughtValue, StackTrace trace) Future<bool>
Sends an HTTP response for a request that yields an exception or error. [...]
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
processRequest(Request req) FutureOr<RequestOrResponse>
Overridden by subclasses to modify or respond to an incoming request. [...]
inherited
toString() String
Returns a string representation of this object.
inherited
willSendResponse(Response response) → void
Executed prior to Response being sent. [...]
inherited

Operators

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