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
- Object
- RequestController
- Router
Constructors
Properties
- basePath → String
-
A string to be prepended to the beginning of every route this
Router
manages.read / write - unhandledRequestController →
-
How this router handles
Request
s that don't match its routes.write-only - documentableChild → APIDocumentable
-
@override, read-only, inherited
- hashCode → int
-
The hash code for this object.
read-only, inherited - logger → Logger
-
read-only, inherited
- nextController → RequestController
-
read / write, 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
Operators
-
operator ==(
other) → bool -
The equality operator.
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(
Future<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 -
The mechanism for delivering a
Request
to this controller for processing. -
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, 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) → Future<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