Using Class Controller

Example

from apidaora import ClassController, appdaora


class HelloWorld(ClassController, path='/hello'):
    def get(self) -> str:
        return 'Hello World!'

    def post(self, body: str) -> str:
        return f'Hello {body}!'


class HelloDuckType:
    path = '/hello-duck'

    def get(self) -> str:
        return 'Hello Duck!'


app = appdaora([HelloWorld, HelloDuckType])

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 the .get method

Quering the server:

curl -i localhost:8000/hello
HTTP/1.1 200 OK
date: Thu, 1st January 1970 00:00:00 GMT
server: uvicorn
content-type: application/json
content-length: 14

"Hello World!"

Quering the .post method

curl -i localhost:8000/hello -X POST -d 'Me'
HTTP/1.1 200 OK
date: Thu, 1st January 1970 00:00:00 GMT
server: uvicorn
content-type: application/json
content-length: 11

"Hello Me!"

Quering the duck type class with .get method

curl -i localhost:8000/hello-duck
HTTP/1.1 200 OK
date: Thu, 1st January 1970 00:00:00 GMT
server: uvicorn
content-type: application/json
content-length: 13

"Hello Duck!"