litestar-lifecycle-hooks

Installation
SKILL.md

Lifecycle Hooks

Use this skill when the requirement is specifically about the request-handler lifecycle for HTTP handlers, not application bootstrapping or whole-ASGI wrapping.

Execution Workflow

  1. Decide which stage matches the requirement: before_request, after_request, or after_response (the exact lifecycle stage needed for behavior injection).
  2. Choose the layer intentionally: app, router, controller, or handler (the layer to place the hook in).
  3. Keep hook behavior small, deterministic, and clearly cross-cutting.
  4. Implement request-state handoff or response mutation explicitly.
  5. Test normal flow, short-circuit flow, and layer-precedence behavior explicitly.

Core Rules

  • Match the hook to the lifecycle stage instead of forcing one hook to do everything.
  • Keep hooks transport-focused and cross-cutting; push domain rules into services or handlers.
  • Keep before_request return values deliberate because any non-None response-compatible value bypasses the route handler.
  • Keep after_request focused on the resolved Response; it may return the same response or a replacement response.
  • Keep after_response side effects safe to run after the response is already sent; it cannot change the response the client received.
Related skills

More from alti3/litestar-skills

Installs
15
GitHub Stars
5
First Seen
Mar 2, 2026