I have an API for random tea photos but would like it to return the photo in JSON as a URL for discord bots and things. This is what I have so far:
def getRandomFile(path):
"""
Returns a random filename, chosen among the files of the given path.
"""
files = os.listdir(path)
index = random.randrange(0, len(files))
return files[index]
@app.get("/")
async def home():
return RedirectResponse("/docs")
@app.get("/tea")
def tea():
x = "teacuppics/{}".format(getRandomFile("teacuppics"))
return FileResponse(x)
How do I swap the reply of images to JSON reply?