title: Download file using fastapi
body: <p>I see the functions for <a href="https://fastapi.tiangolo.com/tutorial/request-files/" rel="noreferrer">uploading in an API</a>, but I don't see how to download. Am I missing something? I want to create an API for a file download site. Is there a different API I should be using?</p>
  <pre><code>from typing import List
  from fastapi import FastAPI, Query
  
  app = FastAPI()
  PATH &quot;some/path&quot;
  
  @app.get(&quot;/shows/&quot;)
      def get_items(q: List[str] = Query(None)):
          '''
          Pass path to function.
          Returns folders and files.
          '''
      
          results = {}
      
          query_items = {&quot;q&quot;: q}
          entry = PATH + &quot;/&quot;.join(query_items[&quot;q&quot;]) + &quot;/&quot;
  
          dirs = os.listdir(entry)
          results[&quot;folders&quot;] = [val for val in dirs if os.path.isdir(entry+val)]
          results[&quot;files&quot;] = [val for val in dirs if os.path.isfile(entry+val)]
          results[&quot;path_vars&quot;] = query_items[&quot;q&quot;]
      
          return results
  </code></pre>
  <p>Here is the sample bit of code for python to fetch files and dirs for a path, you can return the path as a list with a new entry in a loop to go deeper into a file tree. Passing a file name should trigger a download function, but I cant seem to get a download func going.</p>