I have the following method in my API, and I want to make the serve
function a decorator so it can be used like so: @api.serve
.
def add_rule(self, func, methods):
for item in methods:
if item in self._config["MAP"]:
raise RuntimeError("Cannot override functions.")
self._config["MAP"][item] = func
def serve(self, methods=["POST","GET","HEAD"]):
def wrapper(func):
self.add_rule(func, methods)
return func
return wrapper
However, everything doesn't seem to work, i.e. set items within the _config["MAP"]
dictionary. There are no errors, but it isn't doing what it's supposed to do. Can someone give me a hand?