Flask app crashing with 'RuntimeError: Working outside of request context' when using async function
I'm learning this framework and I'm sure I'm missing something obvious here, but I'm currently developing a Flask application using `Flask` version 2.1.1 and trying to implement an asynchronous route to fetch data from an external API. However, I'm working with a `RuntimeError: Working outside of request context` behavior when I try to access the `request` object within my `async` function. Hereβs how my code looks: ```python from flask import Flask, request, jsonify import asyncio import httpx app = Flask(__name__) async def fetch_data(url): async with httpx.AsyncClient() as client: response = await client.get(url) return response.json() @app.route('/data', methods=['GET']) def get_data(): url = request.args.get('url') data = asyncio.run(fetch_data(url)) # This line causes the behavior return jsonify(data) ``` I tried wrapping the call to `fetch_data` inside an `async` function and using `await`, but running into issues since Flask's route handlers are not `async` by default. I also explored using `Quart`, which is an async-compatible Flask alternative, but I would prefer to stick with Flask if possible. How can I properly handle this situation without running into the request context scenario? Any insights or workarounds would be greatly appreciated. The project is a service built with Python. Has anyone dealt with something similar? I'm open to any suggestions.