Skip to content

Commit d1e2a43

Browse files
committed
Update docs
1 parent 07c7ba3 commit d1e2a43

File tree

1 file changed

+53
-1
lines changed

1 file changed

+53
-1
lines changed

docs/web.rst

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,29 @@ argument and returns :class:`StreamResponse` derived
5858
Handler **can** be a :ref:`coroutine<coroutine>`, :mod:`aiohttp.web` will
5959
**unyield** returned result by applying ``yield from`` to handler.
6060

61+
Handlers connected to :class:`Application` via routes::
62+
63+
handler = Handler()
64+
app.router.add_route('GET', '/', handler)
65+
66+
.. _aiohttp-web-variable-handler:
67+
68+
You can also use *variable routes*. If route contains string like
69+
``'/a/{name}/c'`` that means the route matches to path like
70+
``'/a/b/c'`` or ``'/a/1/c'``.
71+
72+
Parsed *path part* will be available in *request handler* as
73+
``request.match_info['name']``::
74+
75+
@asyncio.coroutine
76+
def variable_handler(request):
77+
return web.Response(
78+
request,
79+
"Hello, {}".format(request.match_info['name']).encode('utf8'))
80+
81+
app.router.add_route('GET', '/{name}', variable_handler)
82+
83+
6184
Handlers can be first-class functions like::
6285

6386
@asyncio.coroutine
@@ -735,8 +758,37 @@ Router is any object that implements :class:`AbstractRouter` interface.
735758

736759
Append :ref:`handler<aiohttp-web-handler>` to end of route table.
737760

738-
*path* may be either [TBD]
761+
*path* may be either *contant* string like ``'/a/b/c'`` or
762+
*variable rule* like ``'/a/{var}'`` (see
763+
:ref:`handling variable pathes<aiohttp-web-variable-handler>`)
764+
765+
:param str path: route path
766+
767+
:param callable handler: route handler
768+
769+
.. method:: add_static(prefix, path)
770+
771+
Adds router for returning static files.
772+
773+
Useful for handling static content like images, java script and css files.
774+
775+
.. warning::
776+
777+
Use :meth:`add_static` for development only, in production
778+
static content usually processed by web servers like *nginx*
779+
or *apache*.
780+
781+
:param str prefix: URL path prefix for handled static files
782+
783+
:param str path: path to folder in file system that contains
784+
handled static files.
785+
786+
.. method:: resolve(requst)
739787

788+
A :ref:`coroutine<coroutine>` that returns
789+
:class:`AbstractMatchInfo` for *request* or raises http
790+
exception like :exc:`HTTPNotFound` if there is no registered
791+
route for *request*.
740792

741793
Utilities
742794
---------

0 commit comments

Comments
 (0)