loom.rest.fastapi.router_runtime¶
Router runtime — binds CompiledRoute records to a FastAPI application.
Generates async handler functions at startup, one per
CompiledRoute. Each handler:
Extracts path parameters from
request.path_params(populated by Starlette’s routing layer from the URL).Reads the raw request body and decodes it with
msgspec.json.decodewhen bytes are present.Builds the
UseCaseinstance via theUseCaseFactory.Drives execution through
RuntimeExecutor.Returns a
MsgspecJSONResponse.
Handler __signature__ is manipulated so FastAPI validates and documents
path parameters correctly in OpenAPI while keeping the implementation generic.
No reflection occurs at request time — all structural decisions (path params,
status codes, tags) are taken from the CompiledRoute produced at startup.
Functions
|
|
|
|
|
|
|
Return ordered path-parameter names from a FastAPI path template. |
|
Build an async handler for the given compiled route. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Resolve OpenAPI summary/description from route metadata or UseCase docs. |
|
Register compiled routes on a FastAPI application. |
- loom.rest.fastapi.router_runtime.bind_interfaces(app, compiled_routes, factory, executor)[source]¶
Register compiled routes on a FastAPI application.
For each
CompiledRoute, creates a dynamic async handler and registers it viaapp.add_api_route. Path parameters are inferred from the route path template and exposed in the handler signature so FastAPI validates and documents them correctly.Nested JSON Schema
$defsproduced by msgspec/pydantic are collected into a shared component registry and returned. The caller is responsible for injecting these intocomponents.schemasof the OpenAPI document.- Parameters:
app (fastapi.FastAPI) – FastAPI application instance to register routes on.
compiled_routes (Sequence[CompiledRoute]) – Ordered list of fully resolved routes produced by
RestInterfaceCompiler.factory (UseCaseFactory) – Use-case factory for constructing instances per request.
executor (RuntimeExecutor) – Runtime executor that drives the use-case pipeline.
- Returns:
Mapping of schema name → JSON Schema fragment for all collected
$defsthat should appear undercomponents.schemas.- Return type:
Example:
compiler = RestInterfaceCompiler(use_case_compiler) routes = compiler.compile(UserRestInterface) component_schemas = bind_interfaces(app, routes, factory, executor)