I have a get method as follows:
def get() -> str:
And, I wanted to tweak the final get method response through on_response event hook something like below:
def on_response(self, ret: ReturnValue):
self.message = " To apistar"
ret = ret + self.message
The endpoint triggering get() method should return the response “welcome To apistar”
So basically on_response should be able to return the response either to get() or as a final response. Not sure if it is even possible to do that way.
This being just an example, a real project scenario could be something like I always want to perform data serialization at the end of every get request throughout all project endpoints. It would be nice to have the data serialization done under on_response event hook and return that serialized response (example: date/time serialization, removing keys with null/None values from JSON response,…etc). Likely on the similar basis on_request event hook could perform some pre-processing of data even before going to the core get method logic. All this would be possible only if we could ‘return’ something from event hooks.