Skip to content

Controllers

Instead of defining all route logic as closures, you may organize related actions into controller classes under app/http/controllers.

app/http/controllers/welcome_controller.py
from almasix.http import Controller
from almasix.prism import view
class WelcomeController(Controller):
async def index(self):
return view("welcome", {"title": "Almasix"})

Wire the action in a route file:

routes/web.py
Route.get("/", [WelcomeController, "index"])

Generate a stub:

Terminal window
python smith make:controller PostController

Nested namespaces work (python smith make:controller Admin/UserController) and create __init__.py files as needed.

Constructor and method dependencies are resolved from the application container:

app/http/controllers/demo_controller.py
from almasix.config import ConfigRepository
from almasix.http import Controller, Request
class DemoController(Controller):
def __init__(self, config: ConfigRepository) -> None:
self.config = config
async def with_config(self, request: Request) -> dict:
return {"app": self.config.get("app.name")}

Type-hint Request or a FormRequest subclass to receive the current request (validated when using FormRequest).

Prefer one public index / store / show method per intent. Almasix does not require invokable __call__ controllers — use an explicitly named method on the route.