Route class

Constructors

Route()
factory

Properties

bindings → Map<String, RouteBinding>
binders added with bind
no setter
fallbacks → List<RouteData>
routes added with fallback
no setter
hashCode → int
The hash code for this object.
no setterinherited
hasWebSocketWithoutOriginCheck → bool
true when a websocket route has no allowedOrigins. AppConfig.webSocketAllowedOrigins is not looked at here.
no setter
mounts → Map<String, RawRequestHandler>
raw handlers added with mount
no setter
mountsWithMiddleware → Set<String>
prefixes of the mounts that run the global middleware first
no setter
routes → List<RouteData>
get list of routes registered
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
statics → List<StaticFolder>
folders added with staticFiles
no setter

Methods

name(String name) → Route
name the route added last. a group name: is put in front. the same name twice throws a StateError at start.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
setBindings(Map<String, RouteBinding> bindings) → void
set the binders, eg. in a new isolate
setFallbacks(List<RouteData> fallbacks) → void
set the fallback routes, eg. in a new isolate
setRoutes(List<RouteData> routeList) → void
setStatics(List<StaticFolder> statics) → void
set the static folders, eg. in a new isolate
timeout(Duration duration) → Route
answer 503 when the route added last takes longer than duration. It covers its middleware too. See RequestTimeout.
toString() → String
A string representation of this object.
inherited
where(String param, String regex) → Route
only match the route added last when its param matches regex. Else the route does not match, and the next route is tried (or the client gets 404). The regex must match the whole param text. Use (?:...) for groups, not (...). The value is checked again after % decoding, so the decoded text must match too (a %20 is a space then).

Operators

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

Static Methods

any<T extends Object>(String route, dynamic controller) → Route
one route for GET (and HEAD), POST, PUT, PATCH and DELETE. OPTIONS is left out, so the CORS preflight answer still works.
bind<T extends Object>(String param, RouteBinder<T> resolve) → void
turn the route param param into a value before the controller runs. resolve gets the raw text and gives the value, or null when there is none: then the request gets 404. read it with req.bound<T>(param), or add a controller parameter of type T. call it before the server starts.
copy<T extends Object>(String route, dynamic controller) → Route
copy route
delete<T extends Object>(String route, dynamic controller) → Route
delete route
disabledCors(dynamic callback()) → void
group of route to disabled cors
domain(String domain, dynamic callback()) → void
domain route
enabledCors(dynamic callback()) → void
group of route to enabled cors
fallback<T extends Object>(dynamic controller) → Route
the route for a GET or HEAD request that matches no other route and no staticFiles file. Use it for a custom 404 page, or to send index.html of a single page app. Other methods still get 404 or 405.
get<T extends Object>(String route, dynamic controller) → Route
get route. controller is a function, or with a type T a function that picks the method of a controller from the container.
group(String prefix, dynamic callback(), {String name = ''}) → void
group route. name is put in front of the route names inside.
health(String path, {Map<String, HealthCheckFunction> checks = const <String, HealthCheckFunction>{}, Duration timeout = const Duration(seconds: 5)}) → Route
health check route: GET <path> answers 200 {"status": "ok"}, or 503 when one of the checks fails. See HealthCheck.
link route
lock<T extends Object>(String route, dynamic controller) → Route
lock route
match<T extends Object>(List<String> methods, String route, dynamic controller) → Route
one route for each method in methods, like ['GET', 'POST']. HEAD comes with GET, so leave it out. An unknown method throws an ArgumentError.
middleware(List middleware, dynamic callback()) → void
middleware for group of routes
mount(String prefix, RawRequestHandler handler, {bool middleware = false}) → void
send every request under prefix straight to handler, before routing and body reading. the handler writes and closes the response itself. Socket.IO uses this for /socket.io/.
options<T extends Object>(String route, dynamic controller) → Route
options route
patch<T extends Object>(String route, dynamic controller, {Object? body}) → Route
patch route
permanentRedirect(String from, String to) → Route
redirect with 301 (moved permanently)
post<T extends Object>(String route, dynamic controller, {Object? body}) → Route
post route
prefix(String prefix) → void
set prefix for the route, this will affect its below routes
propfind<T extends Object>(String route, dynamic controller) → Route
propfind route
purge<T extends Object>(String route, dynamic controller) → Route
purge route
put<T extends Object>(String route, dynamic controller, {Object? body}) → Route
put route
redirect(String from, String to, {int status = HttpStatus.found}) → Route
redirect from to to, for every method of any. 302 by default.
resetWithNewMiddleware(List middleware) → void
set global middleware this will remove previous middleware and update new middleware from input input can be list for single middleware
resource(String route, dynamic controller, {String? name}) → Route
resource route. controller is a controller class (a Type) from the container, or a controller object.
signedUrl(String name, {Map<String, Object?> params = const <String, Object?>{}, Map<String, Object?> query = const <String, Object?>{}, Duration? expires, bool absolute = true, String? baseUrl}) → String
url with a signature query param, so the link can not be changed. Check it with the ValidateSignature middleware. With expires, the url also has an expires param (unix seconds) and stops working after that time.
staticFiles(String prefix, String folder, {Duration? maxAge}) → void
serve the files in folder under prefix, for GET and HEAD requests that match no route. Routes always win, so a normal request does not touch the disk. No middleware runs for a file. Like other routes, prefix follows group, the router prefix and domain. folder is relative to the folder the app starts in. Never save user uploads in folder: an uploaded html or svg file would run its script on your site. Use dox_storage for them. .., dot files (like .env) and folders are never sent: they get 404. Only a .well-known folder at the top of folder is sent. A file gets ETag and Last-Modified (and 304 when the browser has it), Range support, and Cache-Control: public, max-age=... with maxAge. Give hashed build files (like Vite's) a long maxAge.
unlink route
unlock<T extends Object>(String route, dynamic controller) → Route
unlock route
unmount(String prefix) → void
remove a handler added with mount
url(String name, {Map<String, Object?> params = const <String, Object?>{}, Map<String, Object?> query = const <String, Object?>{}}) → String
the path of the route named name, with its {params} filled in. a param value is url encoded. query is added as the query string. an unknown name or a missing param throws an ArgumentError.
use(dynamic middleware) → void
add global middleware
view<T extends Object>(String route, dynamic controller) → Route
a route for the WebDAV VIEW HTTP method. It does not render a template like Laravel Route::view. For that, use a GET route: Route.get('welcome', (DoxRequest req) => view(req, 'welcome')) with view() of dox_view.
websocket(String route, WebSocketHandler handler, {List middleware = const <dynamic>[], List<String>? allowedOrigins, int maxMessageSize = 16 * 1024 * 1024}) → Route
raw WebSocket route. handler gets the open socket. Middleware runs first, so it can check auth. For rooms, acks and the socket.io clients, use dox_socketio.