title: How to get current path in FastAPI with domain?
body: <p>I have a simple route as below that written in FastAPI,</p>
  <pre class="lang-py prettyprint-override"><code>from fastapi import FastAPI
  
  app = FastAPI()
  
  
  @app.get(&quot;/foo/bar/{rand_int}/foo-bar/&quot;)
  async def main(rand_int: int):
      return {&quot;path&quot;: f&quot;https://some-domain.com/foo/bar/{rand_int}/foo-bar/?somethig=foo&quot;}
  </code></pre>
  <p>How can I get the current path <em>&quot;programmatically&quot;</em> with,</p>
  <ul>
  <li>domain (<code>some-domain.com</code>)</li>
  <li>path (<code>/foo/bar/{rand_int}/foo-bar/</code>)</li>
  <li>and query parameters (<code>?somethig=foo</code>)</li>
  </ul>