If your API returns long text and you want to compress the response body, the framework will automatically handle this for you.
First, implement a regular endpoint:
@api()
def compress() -> int:
return "long text"The uncompressed API endpoint is:
/api/algorithm/compress
The compressed API endpoint is:
/api/algorithm/compress.zip
If you don't want to handle decompression yourself, use the Python requests API installed with the framework.
import requests
r = requests.get('http://your-host:your-port/api/algorithm/compress.zip')
print(r.status_code) # 200
print(r.text)The response is:
{"code":0,"data":{"sample_rate":null,"sample_count":null,"result":"long text"}}The compressed response is returned with Content-Encoding: gzip. Other clients can decompress it as needed.
To be implemented.