File: quickstart.rst

package info (click to toggle)
hypercorn 0.17.3-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 908 kB
  • sloc: python: 7,839; makefile: 24; sh: 6
file content (41 lines) | stat: -rw-r--r-- 818 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
.. _quickstart:

Quickstart
==========

Hello World
-----------

A very simple ASGI app that simply returns a response containing
``hello`` is, (file ``hello_world.py``)

.. code-block:: python

    async def app(scope, receive, send):
        if scope["type"] != "http":
            raise Exception("Only the HTTP protocol is supported")

        await send({
            'type': 'http.response.start',
            'status': 200,
            'headers': [
                (b'content-type', b'text/plain'),
                (b'content-length', b'5'),
            ],
        })
        await send({
            'type': 'http.response.body',
            'body': b'hello',
        })

and is simply run via

.. code-block:: console

    hypercorn hello_world:app

and tested by

.. code-block:: sh

    curl localhost:8000