Skip to main content Link Menu Expand (external link) Document Search Copy Copied

You can add middlewares with either decorator style or app.add_middleware(). The latter is more suitable in case you are creating an extension.

@app.on_request
async def func(request, **server):
    print('before handler')

behaves the same way as:

app.add_middleware(func, name='request', priority=999)

Available names: 'request' and 'response'.