class
Analyzer::Dart::Shelf
- Analyzer::Dart::Shelf
- Analyzer
- Reference
- Object
Overview
Shelf (package:shelf_router/shelf_router.dart) is the foundational
Dart HTTP server library. The Router API exposes a method per
verb (router.get, router.post, ...) and a mount('/prefix', subRouter) composition primitive. Handlers are typically wired
with cascade operators on a fresh Router():
final router = Router()
..get('/users', _listUsers)
..post('/users', _createUser)
..get('/users/
Direct method calls (router.get('/foo', _handler)) and .all(...)
— which registers a handler against every verb — are also
supported. Path captures use angle brackets (<id>, <id|[0-9]+>)
which we surface as {id} path params.
Mounts are resolved across files: a Router variable mounted under
/prefix contributes its routes (recursively) under that prefix in
the parent router. Each top-level router (not mounted anywhere) is
emitted as a separate set of endpoints.
Defined in:
analyzer/analyzers/dart/shelf.crConstant Summary
-
ALL_VERBS =
["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"] -
HANDLER_REFERENCE_REGEX =
/\A[A-Za-z_]\w*(?:\.[A-Za-z_]\w*)*\z/ -
Matches a bare handler reference (
getNotes,_echo,health_check.handler) passed as the second argument to a route. -
HTTP_METHOD_MAP =
{"get" => "GET", "post" => "POST", "put" => "PUT", "patch" => "PATCH", "delete" => "DELETE", "head" => "HEAD", "options" => "OPTIONS"} -
ROUTE_ANNOTATION_REGEX =
/@Route\s*(?:\.\s*([A-Za-z]+))?\s*\(/ -
Matches the official
@Route.<verb>('/path')annotation and theshelf_router_classes@Route('VERB', '/path')variant. Capture 1 is the dotted verb (nil for the string-arg form). -
ROUTE_PREFIX_REGEX =
/@RoutePrefix\s*\(/