init_http_session

safir.http.init_http_session(app: Application) → AsyncGenerator

Create an aiohttp.ClientSession and make it available as a "safir/httpSession" key on the application.

Parameters

app (aiohttp.web.Application) – The aiohttp.web-based application.

Notes

Use this function as a cleanup context:

app.cleanup_ctx.append(init_http_session)

The session is automatically closed on shut down.

To access the session:

session = app["safir/httpSession"]