Closed njordr closed 7 years ago
Hooks are just something that is ran before or after a request.
For example, a pre hook is a coroutine that takes in the application context, and returns either a) A modified version of it or b) A new context.
@bp.before_request
async def something(ctx):
return MyContext(ctx) # change to your own context class
This is very similar for after_request
, but this just takes in the context and the Response object, and returns a new or modified Response object.
This is useful for things such as an automatic jsonifier, which will turn any dict response body into JSON.
Many thanks
Hi.
Could you please explain in more detail pre and post hooks?