On this page |
In cases where a general purpose url handler is desired over a builtin handler (i.e. @urlHandler or @apiFunction) the URLHandler 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.
Note
The URLHandler is best suited for cases where the handler does not need to wait for other resources before responding. If the request needs to wait for other resources before responding the /hwebserver/AsyncURLHandler.html should be used instead.
Example ¶
This example shows how to create a handler that will call a provided function when a new request comes in. With this class a similar @urlHandler decorator can be created that uses this example.
class URLCallbackHandler(hwebserver.URLHandler): def __init__(self, path, function, is_prefix=False): URLHandler.__init__(self, path, methods=['GET','POST'], allows_partial=is_prefix) self._function = function def handle(self, request): if self._function is None: return hwebserver.errorResponse(request, "Handler doesnt have a function attached.", 500) return self._function(request)
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 |