Debian Codegraph @

docs/tutorials/quickstart.rst

raw
1 .. _quickstart:
2
3 Quickstart
4 ==========
5
6 Hello World
7 -----------
8
9 A very simple ASGI app that simply returns a response containing
10 ``hello`` is, (file ``hello_world.py``)
11
12 .. code-block:: python
13
14 async def app(scope, receive, send):
15 if scope["type"] != "http":
16 raise Exception("Only the HTTP protocol is supported")
17
18 await send({
19 'type': 'http.response.start',
20 'status': 200,
21 'headers': [
22 (b'content-type', b'text/plain'),
23 (b'content-length', b'5'),
24 ],
25 })
26 await send({
27 'type': 'http.response.body',
28 'body': b'hello',
29 })
30
31 and is simply run via
32
33 .. code-block:: console
34
35 hypercorn hello_world:app
36
37 and tested by
38
39 .. code-block:: sh
40
41 curl localhost:8000