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:

Out of scope for this first cut:

Extended Modules

Defined in:

miniparsers/http4k_extractor_ts.cr

Constant Summary

HTTP_VERBS = Set {"GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "TRACE", "CONNECT"}

Instance Method Summary

Instance Method Detail

def extract_routes(source : String, *, include_callees : Bool = false) : Array(Route) #

[View source]