Module h2o_wave.routing

Functions

handle_on

async def handle_on(q: Query) ‑> bool

Handle the query using a query handler (a function annotated with @on()).

Args
q
The query context.
Returns

True if a matching query handler was found and invoked, else False.

on

def on(arg: str = None)

Indicate that a function is a query handler that should be invoked when q.args contains an argument that matches a specific name or pattern.

Examples: A function annotated with @on('foo') is invoked whenever q.args['foo'] is found. A function annotated with @on('#foo') is invoked whenever q.args['#'] equals 'foo'. A function annotated with @on('#foo/bar') is invoked whenever q.args['#'] equals 'foo/bar'. A function annotated with @on('#foo/{fruit}') is invoked whenever q.args['#'] matches 'foo/apple', 'foo/orange', etc. The parameter 'fruit' is passed to the function (in this case, 'apple', 'orange', etc.)

Parameters in patterns (indicated within curly braces) can be converted to str, int, float or uuid.UUID instances by suffixing the parameters with str, int, float or uuid, respectively.

Examples: - user_id:int: user_id is converted to an integer. - amount:float: amount is converted to a float. - id:uuid: id is converted to a uuid.UUID.

Args
arg
The name of the q.arg argument (in case of plain arguments) or a pattern (in case of hash arguments, or q.args['#']). If not provided, the q.arg argument is assumed to be the same as the name of the function.