Right now, I can only view a PlainTextResponse by manually entering the API URL path into my browser. However, I would like to be able to view PlainTextResponses in my Swagger UI. It seems like the OpenAPI loads indefinitely every time I try to request a PlainTextResponse
Here is a sample:
from fastapi import FastAPI
from fastapi.responses import PlainTextResponse
import pandas as pd
app = FastAPI()
@app.get("/plain_text", response_class=PlainTextResponse)
async def plain_text():
url = 'https://raw.githubusercontent.com/ccodwg/Covid19Canada/master/official_datasets/can/phac_n_tests_performed_timeseries_prov.csv'
df = pd.read_csv(url, index_col=0)
return PlainTextResponse(df.to_csv(index=False), media_type="text/plain")
This sample actually works. I'm assuming its because this specific CSV file is relatively small.
However, once you start using larger CSV files, it seems like you are unable to display the response in the UI. For example, try https://raw.githubusercontent.com/Schlumberger/hackathon/master/backend/dataset/data-large.csv instead and it will load forever on the UI but displays relatively quickly if you use the URL path.