On this page
ASGI application factory with middleware chain composition, static file serving, SPA fallback routing, async lifespan hooks, and WebSocket support.
#src.fastware.app
#src.fastware.app
ASGI application factory with middleware chain composition, static file serving, SPA fallback routing, async lifespan hooks, and WebSocket support.
#_send_stream
async def _send_stream(send: Callable, resp: StreamResponse) -> NoneSend a streaming HTTP response, iterating the async generator.
#_deep_convert_pydantic
def _deep_convert_pydantic(obj: Any) -> AnyRecursively convert Pydantic models to plain dicts/lists.
Walks dicts and lists, calling .model_dump(mode="json") on any object that has model_dump (i.e. Pydantic BaseModel instances).
#_send_result
async def _send_result(send: Callable, result: Any) -> NoneDispatch a handler return value to the appropriate sender.
#_serve_static
async def _serve_static(send: Callable, static_dir: Path, rel_path: str) -> boolServe a static file. Returns True if served, False if not found.
#_serve_spa_fallback
async def _serve_spa_fallback(send: Callable, spa_fallback: Path) -> NoneServe the SPA fallback file (typically index.html).
#AppConfig
Configuration for :func:create_app.
All fields correspond to the keyword arguments of create_app. Pass an AppConfig instance as the config parameter, and/or supply individual keyword arguments. Keyword arguments override matching fields on the config object.
#create_app
def create_app(router: Router, config: AppConfig | None=None, **kwargs: Any) -> CallableCreate an ASGI application callable.
Accepts an optional config (:class:AppConfig) and/or keyword arguments. Keyword arguments override matching fields on the config object. If neither is supplied, defaults from AppConfig are used.
If api_prefix is set (e.g. "/api"), the SPA fallback will not serve index.html for paths that start with the prefix -- they fall through to the 404 handler instead.
Built-in middleware (applied when their parameters are truthy):
trusted_hosts: TrustedHostMiddleware (outermost)vite_dev_port: ViteDevProxycors_origins: CORSMiddlewarerequest_id: RequestIDMiddlewarerequest_timing: RequestTimingMiddleware (innermost)
Custom middleware supplied via middleware wraps after built-in middleware (between the app and the built-in stack).