loom.rest.fastapi.app¶
FastAPI application factory.
create_fastapi_app() is the composition root that wires together the
domain bootstrap result and REST interface declarations into a runnable
FastAPI instance.
It is intentionally kept thin — all validation happens during
RestInterfaceCompiler compilation (fail-fast at
startup) and all request handling is delegated to
bind_interfaces().
Usage:
result = bootstrap_app(
config=cfg,
use_cases=[CreateOrderUseCase, GetOrderUseCase],
modules=[register_repositories],
)
app = create_fastapi_app(
result,
interfaces=[OrderRestInterface],
title="Orders API",
version="1.0.0",
)
Functions
|
Patch |
|
Return the application-scoped RuntimeExecutor registered at bootstrap. |
|
Create a FastAPI application from a bootstrap result and REST interfaces. |
- loom.rest.fastapi.app.create_fastapi_app(result, interfaces, *, middleware=(), defaults=None, **fastapi_kwargs)[source]¶
Create a FastAPI application from a bootstrap result and REST interfaces.
Compiles all
RestInterfacedeclarations viaRestInterfaceCompiler, binds each compiled route to theFastAPIinstance, and returns the ready application.Compilation is fail-fast: any structural error (missing use-case plan, duplicate route, missing prefix) raises
InterfaceCompilationErrorbefore the app starts accepting requests.- Parameters:
result (BootstrapResult) – Fully initialised
BootstrapResultfrombootstrap_app().interfaces (Sequence[type[RestInterface[Any]]]) –
RestInterfacesubclasses declaring which endpoints to expose. Compiled in declaration order.ASGI middleware classes to register on the application. Added in declaration order (first = outermost wrapper). Accepts any class compatible with
FastAPI.add_middleware. Example:from loom.rest.middleware import TraceIdMiddleware from loom.prometheus import PrometheusMiddleware app = create_fastapi_app( result, interfaces=[...], middleware=[TraceIdMiddleware, PrometheusMiddleware], )
defaults (RestApiDefaults | None) – Global REST API defaults (pagination mode, profile policy). Falls back to
RestApiDefaultswhen not provided.**fastapi_kwargs (Any) – Additional keyword arguments forwarded to the
FastAPIconstructor (e.g.title,version,docs_url).
- Returns:
Configured
fastapi.FastAPIinstance ready to serve requests.- Raises:
InterfaceCompilationError – If any interface fails structural validation.
- Return type:
fastapi.FastAPI
Example:
app = create_fastapi_app( result, interfaces=[UserRestInterface, OrderRestInterface], defaults=RestApiDefaults(pagination_mode=PaginationMode.CURSOR), title="My API", version="2.0.0", )