On this page |
In cases where a general purpose url handler is desired over a builtin handler (i.e. @urlHandler or @apiFunction) the AsyncURLHandler class can be used. With the general purpose handler other RPC can be built on top (e.g. JSON RPC) while still being able to access all of Houdini. This handler allows for use with asyncio and is therefore Python3 only.
:NOTE
Example ¶
This example shows how to create a handler that will call a provided function when a new request comes in.
class URLCallbackHandler(hwebserver.AsyncURLHandler): def __init__(self, path, function, is_prefix=False): URLHandler.__init__(self, path, methods=['GET','POST'], allows_partial=is_prefix) self._function = function async def handle(self, request): if self._function is None: request.send(hwebserver.errorResponse(request, "Handler doesnt have a function attached.", 500)) return resp = await self._function(request) request.send(resp)
Methods ¶
path
Property
The path the URLHandler is installed on.
methods
Property
The list of methods (GET, POST, etc) the URLHandler is installed on.
See also |