diff --git a/docs/web.rst b/docs/web.rst index c62980f8280..51ad886c27f 100644 --- a/docs/web.rst +++ b/docs/web.rst @@ -661,6 +661,7 @@ and call ``aiohttp_debugtoolbar.setup``:: Debug toolbar is ready to use. Enjoy!!! +.. _aiohttp-web-data-sharing: Data sharing ------------ diff --git a/docs/web_reference.rst b/docs/web_reference.rst index 14bc0446687..878c529cb48 100644 --- a/docs/web_reference.rst +++ b/docs/web_reference.rst @@ -22,6 +22,13 @@ The Request object contains all the information about an incoming HTTP request. Every :ref:`handler` accepts a request instance as the first positional parameter. +A :class:`Request` is a :obj:`dict`-like object, allowing it to be used for +:ref:`sharing data` among +:ref:`aiohttp-web-middlewares` and :ref:`aiohttp-web-signals` handlers. + +Although :class:`Request` is :obj:`dict`-like object, it can't be duplicated +like one using :meth:`Request.copy`. + .. note:: You should never create the :class:`Request` instance manually -- @@ -897,9 +904,10 @@ factory*. *RequestHandlerFactory* could be constructed with *Application* contains a *router* instance and a list of callbacks that will be called during application finishing. -*Application* is a :class:`dict`, so you can use it as registry for -arbitrary properties for later access from -:ref:`handler` via :attr:`Request.app` property:: +:class:`Application` is a :obj:`dict`-like object, so you can use it for +:ref:`sharing data` globally by storing arbitrary +properties for later access from a :ref:`handler` via the +:attr:`Request.app` property:: app = Application(loop=loop) app['database'] = await aiopg.create_engine(**db_config) @@ -908,6 +916,8 @@ arbitrary properties for later access from with (await request.app['database']) as conn: conn.execute("DELETE * FROM table") +Although :class:`Application` is a :obj:`dict`-like object, it can't be +duplicated like one using :meth:`Application.copy`. .. class:: Application(*, loop=None, router=None, logger=, \ middlewares=(), **kwargs)