module
Noir::TreeSitterHttp4kExtractor
Overview
Tree-sitter-backed http4k extractor.
http4k uses Kotlin's infix-call syntax to register routes inside
a top-level routes(...) call:
val app = routes(
"/users" bind GET to { req: Request -> ... },
"/users/{id}" bind POST to ::createUser,
"/api" bind routes(
"/status" bind GET to handler,
"/v1" bind routes(
"/health" bind Method.GET to other
)
)
)
path bind VERB to handler is parsed as a nested infix_expression
— the inner bind glues path to verb, the outer to attaches the
handler. path bind routes(...) is the prefix-grouping form.
Recognised:
- Verbs
GET,POST,PUT,DELETE,PATCH,HEAD,OPTIONS,TRACE,CONNECT— both bare (GET) andMethod.GET-qualified. - Inline lambda handler — scanned for
req.query("name"),req.header("X-Foo"),req.form("x"),req.bodyString()calls.req.path("id")is skipped (the URL placeholder already carries it; the optimizer synthesises a path Param). path bind routes(...)— prefix composition withsingle-/joining.
Out of scope for this first cut:
- Lens-based body / form / header (
Body.auto<T>(),Header.required("X")). These are powerful but require cross-call value tracking — a follow-up. - Callable-reference handlers (
::myHandler) — we emit the route without scanning the function's body. static/singlePageAppfor static asset routes.
Extended Modules
Defined in:
miniparsers/http4k_extractor_ts.crConstant Summary
-
HTTP_VERBS =
Set {"GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "TRACE", "CONNECT"}