'Azure function HTTP response type to make the API download a csv whenever get response called

new_csv = df.to_csv('sample.csv', index=False, encoding='utf-8')
return func.HttpResponse(new_csv, index=False, encoding='utf-8', mimetype='text/csv')

How can I pass the CSV file as a GET response to the func.HttpResponse in Azure functions, so that whenever the API is hit, the CSV file gets automatically downloaded as get response method.

        with open(filename, 'rb') as f:
            return func.HttpResponse(
            body=f.read(),
            mimetype='text/csv',
            status_code=200
        )

This piece of http response does the job of returning CSV_as_response but the file has to be statically present in the local system.

What I want is a json data -> CSV -> csv as response



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source