@@ -58,6 +58,29 @@ argument and returns :class:`StreamResponse` derived
58
58
Handler **can ** be a :ref: `coroutine<coroutine> `, :mod: `aiohttp.web ` will
59
59
**unyield ** returned result by applying ``yield from `` to handler.
60
60
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
+
61
84
Handlers can be first-class functions like::
62
85
63
86
@asyncio.coroutine
@@ -735,8 +758,37 @@ Router is any object that implements :class:`AbstractRouter` interface.
735
758
736
759
Append :ref: `handler<aiohttp-web-handler> ` to end of route table.
737
760
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)
739
787
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 *.
740
792
741
793
Utilities
742
794
---------
0 commit comments