Skip to content
Advertisement

How to get current path in FastAPI with domain?

I have a simple route as below that written in FastAPI,

JavaScript

How can I get the current path “programmatically” with,

  • domain (some-domain.com)
  • path (/foo/bar/{rand_int}/foo-bar/)
  • and query parameters (?somethig=foo)

Advertisement

Answer

We can use the Request.url-(starlette doc) API to get the various URL properties. To get the absolute URL, we need to use the Request.url._url private API , as below

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement