Router
Index
Methods
__call__
Invoke a request handler that matches the request label (or the default).
Parameters
context: TCrawlingContext
Returns None
__init__
Returns None
default_handler
Register a default request handler.
The default request handler is invoked for requests that have either no label or a label for which we have no matching handler.
Parameters
handler: RequestHandler[TCrawlingContext]
Returns RequestHandler[TCrawlingContext]
handler
Register a request handler based on a label.
This decorator registers a request handler for a specific label. The handler will be invoked only for requests that have the exact same label.
Parameters
label: str
Returns Callable[[RequestHandler[TCrawlingContext]], Callable[[TCrawlingContext], Awaitable]]
A request dispatching system that routes requests to registered handlers based on their labels.
The
Router
allows you to define and register request handlers for specific labels. When a request is received, the router invokes the correspondingrequest_handler
based on the request'slabel
. If no matching handler is found, the default handler is used.Usage