Web API Reference
API reference for myfy-web package.
Routes
Web Module
WebModule
Web module - provides HTTP server capabilities.
Features: - FastAPI-like routing with @route.get/post/etc decorators - Automatic DI injection in handlers - Request-scoped dependencies - ASGI standard (works with uvicorn, hypercorn, etc.)
Create web module.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
router
|
Router | None
|
Custom router (defaults to global route decorator instance) |
None
|
Source code in packages/myfy-web/myfy/web/module.py
configure
Configure web module.
Registers WebSettings, Router, and ASGI app in the DI container.
Note: In nested settings pattern (ADR-0007), WebSettings is registered by Application. Otherwise, load standalone WebSettings.
Source code in packages/myfy-web/myfy/web/module.py
start
async
stop
async
get_asgi_app
Get the ASGI application.
Note: This method is primarily for the myfy run command.
The myfy start command uses the factory pattern instead
(see myfy.web.factory.create_asgi_app_with_lifespan).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
container
|
DI container |
required | |
lifespan
|
Optional lifespan context manager for module startup/shutdown |
None
|
Returns:
| Type | Description |
|---|---|
ASGIApp
|
ASGIApp instance |
Source code in packages/myfy-web/myfy/web/module.py
Handlers
handlers
Handler execution with dependency injection.
Compiles injection plans for routes at startup.
HandlerExecutor
Executes route handlers with dependency injection.
Resolves dependencies from the DI container and injects them along with path parameters and request body.
Source code in packages/myfy-web/myfy/web/handlers.py
compile_route
Compile an execution plan for a route.
Analyzes the handler signature and builds a fast execution path.
Source code in packages/myfy-web/myfy/web/handlers.py
execute_route
async
Execute a route handler.
Source code in packages/myfy-web/myfy/web/handlers.py
ASGI
asgi
ASGI adapter using Starlette.
Integrates myfy routing and DI with ASGI protocol.
ASGIApp
ASGI application adapter.
Bridges myfy routes and DI with Starlette's ASGI implementation.
Create ASGI app.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
container
|
Any
|
DI container (must be compiled) |
required |
router
|
Router
|
Router with registered routes |
required |
lifespan
|
Any
|
Lifespan context manager (optional) |
None
|