I want to run multiple requests in concurrency in Python FastAPI, my current py file script.py
is as follows:
from fastapi import FastAPI
import time
app = FastAPI()
@app.get('/')
async def func(text: str):
time.sleep(5)
return {'text': text}
I run the API using uvicorn script:app --reload
and calling the endpoint http://127.0.0.1:8000/?text=test
When making 3 requests at the same time to this endpoint, I get the 1st response in 5 seconds, the 2nd response in 10 seconds, and the 3rd in 15 seconds.
How can I run the 3 requests in parallel to return them all in 5 seconds?