Skip to content

Commit

Permalink
Update info about Request & Application dict-like usage.
Browse files Browse the repository at this point in the history
  • Loading branch information
jashandeep-sohi committed Oct 29, 2015
1 parent 237cdc9 commit e83a72e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/web.rst
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,7 @@ and call ``aiohttp_debugtoolbar.setup``::
Debug toolbar is ready to use. Enjoy!!!
.. _aiohttp-web-data-sharing:
Data sharing
------------
Expand Down
16 changes: 13 additions & 3 deletions docs/web_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ The Request object contains all the information about an incoming HTTP request.
Every :ref:`handler<aiohttp-web-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<aiohttp-web-data-sharing>` 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 --
Expand Down Expand Up @@ -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<aiohttp-web-handler>` via :attr:`Request.app` property::
:class:`Application` is a :obj:`dict`-like object, so you can use it for
:ref:`sharing data<aiohttp-web-data-sharing>` globally by storing arbitrary
properties for later access from a :ref:`handler<aiohttp-web-handler>` via the
:attr:`Request.app` property::

app = Application(loop=loop)
app['database'] = await aiopg.create_engine(**db_config)
Expand All @@ -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=<default>, \
middlewares=(), **kwargs)
Expand Down

0 comments on commit e83a72e

Please sign in to comment.