title: How can I send an HTTP request from my FastAPI app to another site (API)?
body: <p>I am trying to send 100 requests at a time to a server <code>http://httpbin.org/uuid</code> using the following code snippet <br></p>
  <pre><code>from fastapi import FastAPI
  from time import sleep
  from time import time
  import requests
  import asyncio
  
  app = FastAPI()
  
  URL= &quot;http://httpbin.org/uuid&quot;
  
  
  # @app.get(&quot;/&quot;)
  async def main():
      r = requests.get(URL)
      # print(r.text)
      
      return r.text
  
  async def task():
      tasks = [main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main(),main()]
      # print(tasks)
      # input(&quot;stop&quot;)
      result = await asyncio.gather(*tasks)
      print (result)
  
  @app.get('/')
  def f():
      start = time()
      asyncio.run(task())
      print(&quot;time: &quot;,time()-start)
  </code></pre>
  <p>I am using FastAPI with Asyncio to achieve the lowest time possible around 3 seconds or less but using the above method I am getting an overall time of 66 seconds that is more than a minute. I also want to keep the <code>main</code> function for additional operations on <code>r.text</code>. I understand that to achieve such low time, concurrency is required but I am not sure what mistake I'm doing here.</p>