Skip to content
This repository has been archived by the owner on Aug 7, 2019. It is now read-only.

Latest commit

 

History

History
117 lines (86 loc) · 4.23 KB

README.md

File metadata and controls

117 lines (86 loc) · 4.23 KB

asgi-examples

ASGI (Asynchronous Server Gateway Interface) examples and information.

ASGI application example

Here are two examples of writing an ASGI application in its simplest form.

As a function

def app(scope):
    async def asgi(receive, send):
        await send(
            {
                "type": "http.response.start",
                "status": 200,
                "headers": [[b"content-type", b"text/plain"]],
            }
        )
        await send({"type": "http.response.body", "body": b"Hello, world!"})

    return asgi

As a class

class App:
    def __init__(self, scope):
        self.scope = scope

    async def __call__(self, receive, send):
        await send(
            {
                "type": "http.response.start",
                "status": 200,
                "headers": [[b"content-type", b"text/plain"]],
            }
        )
        await send({"type": "http.response.body", "body": b"Hello, world!"})

Frameworks / Adapters / Middlewares

Below are various frameworks, adapters, and middlewares that use ASGI.

Servers

Tools

Running the applications

An ASGI server is required to run the examples. For example, to run an application using uvicorn, use the following command:

$ uvicorn app:app

Reference

Below are links to various ASGI-related projects and information.

Specification

Misc

Discussions

Contributing

Please open an issue or pull request if you would like to contribute to the examples or README. The issue tracker may also be used for any informal ASGI-related discussions or questions.