title: How does FastAPI's application mounting works?
body: <p>For certain reasons, we have chosen the <a href="https://fastapi.tiangolo.com/" rel="nofollow noreferrer">FastAPI</a>, in order to use it as back-end tier of our multi-module production. One of its attractive features is sub application, that helps us to separate different modules with intention of making it more modular. But we are <em><strong>concerned</strong></em> about some possible deficiencies which are missing in the official documentation. There are a considerable amount of common things -- e.g data, services, etc -- that we need to share them between main module and submodule through plugins, middle-wares and dependency-injection. The questions are: <strong>Is this feature good enough for separate modules?</strong> and so: <strong>Do sub applications inherit middle-ware, plugins and dependency injection from parent app?</strong></p>
  <p><em>thanks for sharing your experiences.</em></p>
  <p><a href="https://fastapi.tiangolo.com/advanced/sub-applications/" rel="nofollow noreferrer">the sample code in the official docs </a></p>
  <pre><code>from fastapi import FastAPI
  
  app = FastAPI()
  
  
  @app.get(&quot;/app&quot;)
  def read_main():
      return {&quot;message&quot;: &quot;Hello World from main app&quot;}
  
  
  subapi = FastAPI()
  
  
  @subapi.get(&quot;/sub&quot;)
  def read_sub():
      return {&quot;message&quot;: &quot;Hello World from sub API&quot;}
  
  
  app.mount(&quot;/subapi&quot;, subapi)
  </code></pre>