@@ -61,6 +61,31 @@ def __init__(
6161 lifespan = None ,
6262 request_id = False ,
6363 ):
64+ """Create a new Responder API instance.
65+
66+ :param debug: If ``True``, enable debug mode with verbose error pages.
67+ :param title: The title of the API, used in OpenAPI documentation.
68+ :param version: The version string for the API (e.g. ``"1.0"``).
69+ :param description: A longer description of the API for OpenAPI docs.
70+ :param terms_of_service: URL to the API's terms of service.
71+ :param contact: Contact information dict for the API (``name``, ``url``, ``email``).
72+ :param license: License information dict (``name``, ``url``).
73+ :param openapi: The OpenAPI version string (e.g. ``"3.0.2"``). Enables OpenAPI schema generation.
74+ :param openapi_route: The URL path for the OpenAPI schema (default ``"/schema.yml"``).
75+ :param static_dir: Directory for static files. Set to ``None`` to disable. Created automatically if missing.
76+ :param static_route: URL prefix for serving static files (default ``"/static"``).
77+ :param templates_dir: Directory for Jinja2 templates (default ``"templates"``).
78+ :param auto_escape: If ``True``, auto-escape HTML/XML in templates.
79+ :param secret_key: Secret key for signing cookie-based sessions. **Always set this in production.**
80+ :param enable_hsts: If ``True``, redirect all HTTP requests to HTTPS.
81+ :param docs_route: URL path for interactive API docs (e.g. ``"/docs"``). Enables OpenAPI if not already set.
82+ :param cors: If ``True``, enable CORS middleware.
83+ :param cors_params: Dict of CORS configuration (``allow_origins``, ``allow_methods``, etc.).
84+ :param allowed_hosts: List of allowed hostnames (e.g. ``["example.com"]``). Defaults to ``["*"]``.
85+ :param openapi_theme: Documentation UI theme: ``"swagger_ui"``, ``"redoc"``, ``"rapidoc"``, or ``"elements"``.
86+ :param lifespan: An async context manager for startup/shutdown logic.
87+ :param request_id: If ``True``, add ``X-Request-ID`` headers to all responses.
88+ """ # noqa: E501
6489 self .background = BackgroundQueue ()
6590
6691 self .secret_key = secret_key
@@ -150,12 +175,30 @@ def requests(self):
150175
151176 @property
152177 def static_app (self ):
178+ """The Starlette ``StaticFiles`` application for serving static assets."""
153179 if not hasattr (self , "_static_app" ):
154180 assert self .static_dir is not None
155181 self ._static_app = StaticFiles (directory = self .static_dir )
156182 return self ._static_app
157183
158184 def before_request (self , websocket = False ):
185+ """Register a function to run before every request.
186+
187+ If the hook sets ``resp.status_code``, the route handler is skipped
188+ and the response is sent immediately (short-circuiting).
189+
190+ :param websocket: If ``True``, register as a WebSocket before-request hook instead of HTTP.
191+
192+ Usage::
193+
194+ @api.before_request()
195+ def check_auth(req, resp):
196+ if "Authorization" not in req.headers:
197+ resp.status_code = 401
198+ resp.media = {"error": "unauthorized"}
199+
200+ """ # noqa: E501
201+
159202 def decorator (f ):
160203 self .router .before_request (f , websocket = websocket )
161204 return f
@@ -180,6 +223,21 @@ def decorator(f):
180223 return decorator
181224
182225 def add_middleware (self , middleware_cls , ** middleware_config ):
226+ """Add ASGI middleware to the application.
227+
228+ Middleware wraps the entire application and can inspect or modify
229+ every request and response. Middleware is applied in reverse order —
230+ the last middleware added runs first.
231+
232+ :param middleware_cls: A Starlette-compatible middleware class.
233+ :param middleware_config: Keyword arguments passed to the middleware constructor.
234+
235+ Usage::
236+
237+ from starlette.middleware.httpsredirect import HTTPSRedirectMiddleware
238+ api.add_middleware(HTTPSRedirectMiddleware)
239+
240+ """
183241 self .app = middleware_cls (self .app , ** middleware_config )
184242
185243 def exception_handler (self , exception_cls ):
@@ -501,6 +559,10 @@ def serve(self, *, address=None, port=None, debug=False, **options):
501559 uvicorn .run (self , host = address , port = port , ** options )
502560
503561 def run (self , ** kwargs ):
562+ """Run the application. Shorthand for :meth:`serve` that inherits the ``debug`` setting.
563+
564+ :param kwargs: Keyword arguments passed through to :meth:`serve`.
565+ """
504566 if "debug" not in kwargs :
505567 kwargs .update ({"debug" : self .debug })
506568 self .serve (** kwargs )
0 commit comments