class
Analyzer::Dart::DartFrog
- Analyzer::Dart::DartFrog
- Analyzer
- Reference
- Object
Overview
Dart Frog is a filesystem-routed framework. Routes live under
routes/ and the URL is derived from the directory layout:
routes/index.dart → / routes/about.dart → /about routes/users/index.dart → /users routes/users/[id].dart → /users/{id} routes/users/[id]/posts.dart → /users/{id}/posts
Each route file exports an onRequest(RequestContext, ...) handler.
Method dispatch happens inside that handler — typically a switch on
context.request.method against HttpMethod.<verb> constants. We
surface the verbs we can see referenced in the file and fall back
to the standard set when the file looks like a catch-all (no
explicit HttpMethod.* references).
_middleware.dart and other underscore-prefixed Dart files are
framework plumbing — not user-facing routes — and skipped.
Defined in:
analyzer/analyzers/dart/dart_frog.crConstant Summary
-
CASE_METHOD_REGEX =
/\bcase\s+HttpMethod\.([a-z]+)\s*:/ -
Matches
case HttpMethod.<verb>:clauses inside a method switch. -
CLAUSE_BOUNDARY_REGEX =
/\}|\bcase\b|\bdefault\b/ -
The handler body for a
caseclause runs until the next clause or the closing brace of the switch — whichever comes first. We bound at the earliest of a}, acase, or adefaultkeyword so the last enumerated method-case can't sweep in a trailingdefault:arm (whose405/methodNotAllowedwould wrongly tar the case). -
FALLBACK_METHODS =
["GET", "POST", "PUT", "DELETE", "PATCH"] -
HANDLER_REFERENCE_REGEX =
/\A[A-Za-z_]\w*(?:\.[A-Za-z_]\w*)*\z/ -
A bare (possibly dotted) handler reference assigned to
onRequest. -
HTTP_METHOD_MAP =
{"get" => "GET", "post" => "POST", "put" => "PUT", "delete" => "DELETE", "patch" => "PATCH", "head" => "HEAD", "options" => "OPTIONS"} -
HTTP_METHOD_PATTERNS =
HTTP_METHOD_MAP.map do |dart_name, verb| {verb, /HttpMethod\.#{dart_name}\b/} end -
Crystal recompiles an interpolated regex literal on every evaluation (a full PCRE2 JIT compile) — precompile the fixed verb probes once at load time instead of per handler file.
-
METHOD_NOT_ALLOWED_REGEX =
/methodNotAllowed|MethodNotAllowed|statusCode\s*:\s*405|\(\s*405\b/ -
A clause body that rejects the verb:
methodNotAllowed,MethodNotAllowedResponse(), or a literal405status code passed positionally (Response(405)) or by name (statusCode: 405). We deliberately avoid a bare405so an unrelated{'code': 405}in a real handler body can't be mistaken for a rejection. -
ON_REQUEST_HANDLER_REGEX =
/\bonRequest\s*[(=]/ -
Every Dart Frog route file exports an
onRequesthandler — either a function (Response onRequest(...),Future<Response> onRequest(...)) or the assignment form (Handler onRequest = ...). A.dartfile under aroutes/directory that lacks it is not a server route. This matters for full-stack monorepos, where a Flutter client commonly keeps its UI navigation underlib/.../routes/— those widget files must not be reported as HTTP endpoints.