A collection of example ASGI applications
ASGI (Asynchronous Server Gateway Interface) examples and information.
Here are two examples of writing an ASGI application in its simplest form.
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
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!"})
Below are various frameworks, adapters, and middlewares that use ASGI.
An ASGI server is required to run the examples. For example, to run an application using uvicorn
, use the following command:
$ uvicorn app:app
Below are links to various ASGI-related projects and information.
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.