Using ASGI module

Example

from typing import TypedDict

from jsondaora import jsondaora, typed_dict_asjson

from apidaora.core import JSON_RESPONSE, appdaora_core, route


@jsondaora
class You(TypedDict):
    name: str
    location: str


@route.get('/hello/{name}', query=True)
async def hello_controller(request):  # type: ignore
    you = You(
        name=request.path_args['name'],
        location=request.query_dict['location'][0],
    )
    body = typed_dict_asjson(you, You)
    return JSON_RESPONSE, body


app = appdaora_core(hello_controller)

Running

Running the server:

uvicorn myapp:app
INFO: Started server process [16220]
INFO: Waiting for application startup.
INFO: ASGI 'lifespan' protocol appears unsupported.
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)

Quering

Quering the server:

curl -i localhost:8000/hello/Me?location=World
HTTP/1.1 200 OK
date: Thu, 1st January 1970 00:00:00 GMT
server: uvicorn
content-type: application/json
transfer-encoding: chunked

{"name":"Me","location":"World"}