@@ -33,6 +33,9 @@ http://aiohttp.readthedocs.org/
33
33
Getting started
34
34
---------------
35
35
36
+ Client
37
+ ^^^^^^
38
+
36
39
To retrieve something from the web::
37
40
38
41
import aiohttp
@@ -48,56 +51,38 @@ powered program::
48
51
body = yield from response.read()
49
52
print(body)
50
53
51
- The signature of request is the following::
52
-
53
- request(method, url, *,
54
- params=None,
55
- data=None,
56
- headers=None,
57
- cookies=None,
58
- auth=None,
59
- allow_redirects=True,
60
- max_redirects=10,
61
- encoding='utf-8',
62
- version=aiohttp.HttpVersion11,
63
- compress=None,
64
- chunked=None,
65
- expect100=False,
66
- connector=None,
67
- read_until_eof=True,
68
- request_class=None,
69
- response_class=None,
70
- loop=None
71
- )
72
-
73
- It constructs and sends a request. It returns response object. Parameters are explained as follow:
74
-
75
- - ``method ``: HTTP method
76
- - ``url ``: Request url
77
- - ``params ``: (optional) Dictionary or bytes to be sent in the query string
78
- of the new request
79
- - ``data ``: (optional) Dictionary, bytes, StreamReader or file-like object to
80
- send in the body of the request
81
- - ``headers ``: (optional) Dictionary of HTTP Headers to send with the request
82
- - ``cookies ``: (optional) Dict object to send with the request
83
- - ``auth ``: (optional) `BasicAuth ` tuple to enable Basic HTTP Basic Auth
84
- - ``allow_redirects ``: (optional) Boolean. Set to True if POST/PUT/DELETE
85
- redirect following is allowed.
86
- - ``version ``: Request http version.
87
- - ``compress ``: Boolean. Set to True if request has to be compressed
88
- with deflate encoding.
89
- - ``chunked ``: Boolean or Integer. Set to chunk size for chunked
90
- transfer encoding.
91
- - ``expect100 ``: Boolean. Expect 100-continue response from server.
92
- - ``connector ``: ``aiohttp.connector.BaseConnector `` instance to support
93
- connection pooling and session cookies.
94
- - ``read_until_eof ``: Read response until eof if response
95
- does not have Content-Length header.
96
- - ``request_class ``: Custom Request class implementation.
97
- - ``response_class ``: Custom Response class implementation.
98
- - ``loop ``: Optional event loop.
99
-
100
54
If you want to use timeouts for aiohttp client side please use standard
101
55
asyncio approach::
102
56
103
57
yield from asyncio.wait_for(request('GET', url), 10)
58
+
59
+ Server (experimental)
60
+ ^^^^^^^^^^^^^^^^^^^^^
61
+
62
+ In aiohttp 0.10 we've added highlevel API for web HTTP server.
63
+
64
+ There is simple usage example::
65
+
66
+ import asyncio
67
+ from aiohttp import web
68
+
69
+
70
+ @asyncio.coroutine
71
+ def handle(request):
72
+ name = request.match_info.get('name', "Anonymous")
73
+ text = "Hello, " + name
74
+ return web.Response(body=text.encode('utf-8')
75
+
76
+
77
+ @asyncio.coroutine
78
+ def init(loop):
79
+ app = Application(loop=loop)
80
+ app.router.add_route('GET', '/{name}', handle)
81
+
82
+ srv = yield from loop.create_server(app.make_handler, '127.0.0.1', 8080)
83
+ print("Server started at http://127.0.0.1:8080")
84
+ return srv
85
+
86
+ loop = asyncio.get_event_loop()
87
+ loop.run_until_complete(init(loop))
88
+ loop.run_forever()
0 commit comments