Using the gzip request body

Example

from apidaora import GZipFactory, appdaora, route


class GzipBody(GZipFactory):
    mode = 'rt'


@route.post('/hello')
def gzip_hello(body: GzipBody) -> str:
    with body.open() as file:
        return file.read()


app = appdaora(gzip_hello)

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)

Posting gzip file

Posting the file to the api (needs gzip installed):

echo -n 'Hello World!' | gzip > hello.gz

curl -X POST -i localhost:8000/hello --upload-file hello.gz
HTTP/1.1 100 Continue

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!"