router library
Routing: the request tree, how it is composed, and how it is inspected.
Import this when an application only wires routes and needs nothing else, for example a composition file that assembles generated modules.
import 'package:dust_server/router.dart';
final app = Router()
..route('/health', get(health))
..nest('/api/v1', v1)
..layer(Cors())
..withState(repo);
Everything here is also exported from package:dust_server/server.dart.
Classes
- CatchAllSegment
-
{*name}: the rest of the path, captured. - ConstrainedSegment
-
{name|pattern}: one segment matching the caller's own pattern. - DisposableLayer
- A Layer that owns something and needs telling when the server stops.
- Layer
- Middleware that can be written as a const expression.
- LiteralSegment
- Text that has to appear as written.
- MethodRouter
- The handlers registered for one path, keyed by method.
- MountedRoute
- One route as it is actually served, for anything that inspects the app.
- ParameterSegment
-
{name}: one segment, captured. - PathSegment
- One segment of a route path, after parsing.
- Request
- An HTTP request to be processed by a Shelf application.
- Response
- The response returned by a Handler.
- Route
- One route in a router.
- Router
- A tree of routes, composed at startup.
- Service
- Something that answers a request.
Extensions
- RouterDescribe on Router
- Route introspection, kept off the router's core so that serving requests and describing them stay separable.
Functions
-
any<
T> (Endpoint< T> endpoint, {int status = 200}) → MethodRouter -
Serves
endpointfor any method no other handler claims. -
compilePath(
String path, {bool isMount = false}) → RegExp - Compiles a route path into a matcher.
-
connect<
T> (Endpoint< T> endpoint, {int status = 200}) → MethodRouter -
Serves
endpointforCONNECT. -
delete<
T> (Endpoint< T> endpoint, {int status = 200}) → MethodRouter -
Serves
endpointforDELETE. -
get<
T> (Endpoint< T> endpoint, {int status = 200}) → MethodRouter -
Serves
endpointforGET. -
head<
T> (Endpoint< T> endpoint, {int status = 200}) → MethodRouter -
Serves
endpointforHEAD. -
joinPaths(
String prefix, String suffix) → String - Joins two path segments, normalizing both.
-
normalizePrefix(
String value) → String -
Normalizes one path segment into
''or/segmentform. -
options<
T> (Endpoint< T> endpoint, {int status = 200}) → MethodRouter -
Serves
endpointforOPTIONS. -
parameterNames(
String path) → List< String> - The parameter names a route path declares, in order.
-
patch<
T> (Endpoint< T> endpoint, {int status = 200}) → MethodRouter -
Serves
endpointforPATCH. -
post<
T> (Endpoint< T> endpoint, {int status = 200}) → MethodRouter -
Serves
endpointforPOST. -
put<
T> (Endpoint< T> endpoint, {int status = 200}) → MethodRouter -
Serves
endpointforPUT. -
resolveMiddleware(
List< Object> entries) → List<Middleware> - Turns a mixed list of Layer and shelf Middleware values into shelf middleware, keeping the order they were written in.
-
trace<
T> (Endpoint< T> endpoint, {int status = 200}) → MethodRouter -
Serves
endpointforTRACE.
Typedefs
-
Endpoint<
T> = FutureOr< T> Function(Request request) - What a verb builder accepts: a function of the request that returns whatever the endpoint produced.
-
Handler
= FutureOr<
Response> Function(Request request) - A function which handles a Request.
- Middleware = Handler Function(Handler innerHandler)
- A function which creates a new Handler by wrapping a Handler.