What problem does it solve?
This Skill eliminates the guesswork and common errors when configuring Litestar's built-in and custom ASGI middleware, ensuring correct scope filtering, ordering, and separation of cross-cutting concerns from business logic.
Core Features & Use Cases
- Built-in Middleware Configuration: Guidance for using Litestar's pre-built middleware for CORS, CSRF, compression, request IDs, and allowed hosts out of the box.
- Custom ASGI Middleware Patterns: Reusable templates for cross-cutting concerns like request timing, structured logging, and JWT authentication that auto-loads users onto the connection object.
- Scope and Ordering Best Practices: Rules for filtering middleware to specific ASGI scopes (HTTP/WebSocket) and setting intentional middleware order to avoid unexpected behavior.
- Use Case: For example, if you need to add request timing that only applies to HTTP endpoints and skips health check paths, this Skill provides the exact implementation pattern to avoid affecting WebSocket traffic or adding overhead to noise endpoints.
Quick Start
Use the litestar-middleware skill to implement a custom timing middleware that only runs for HTTP requests, excludes /health and /metrics paths, and logs request duration in milliseconds.