Jaymon / endpoints

Lightweight REST api backend framework that automatically maps urls to python modules and classes
MIT License
29 stars 10 forks source link

ASGI interface module #116

Closed Jaymon closed 1 year ago

Jaymon commented 3 years ago

From the docs:

ASGI (Asynchronous Server Gateway Interface) is a spiritual successor to WSGI, intended to provide a standard interface between async-capable Python web servers, frameworks, and applications.

Heard about this from here:

If you are starting a new project, you might benefit from a newer and faster framework based on ASGI instead of WSGI (Flask and Django are WSGI-based).

...Also, if you want to use new technologies like WebSockets it would be easier (and possible) with a newer framework based on ASGI, like FastAPI or Starlette. As the standard ASGI was designed to be able to handle asynchronous code like the one needed for WebSockets.

Check out Starlette, Uvicorn, or FastAPI to see how it is implemented. It looks like FastAPI depends on Starlette, and Starlette is using Anyio as an underlying library. This module: asgiref also looks useful.

The current reference server is Daphne:

The current ASGI reference server, written in Twisted and maintained as part of the Django Channels project. Supports HTTP/1, HTTP/2, and WebSockets.

Jaymon commented 2 years ago

https://github.com/Jaymon/endpoints/issues/118

Jaymon commented 2 years ago

Links I had open

Search

Jaymon commented 2 years ago

Some notes I had open while messing with Daphne:

daphne -b 0.0.0.0 -p 4000 asgi:application

pip install daphne

request object:
args (1) =
(
    0:
        {
            'type': "http",
            'http_version': "1.1",
            'method': "GET",
            'path': "/foo/bar",
            'raw_path': b'/foo/bar',
            'root_path': "",
            'scheme': "http",
            'query_string': b'',
            'headers':
                [
                    0:
                        (
                            0: b'host',
                            1: b'localhost:4000'
                        ),
                    1:
                        (
                            0: b'user-agent',
                            1: b'curl/7.58.0'
                        ),
                    2:
                        (
                            0: b'accept',
                            1: b'*/*'
                        )
                ],
            'client':
                [
                    0: "127.0.0.1",
                    1: 33958
                ],
            'server':
                [
                    0: "127.0.0.1",
                    1: 4000
                ],
            'asgi':
                {
                    'version': "3.0"
                }
        }
)