FastAPI Helper¶
Note
FastAPI Helper Module need FastAPI
installed.
There are two helper modules to get FastAPI app
/router
for proxy conveniently.
- fastapi_proxy_lib.fastapi.app: High-level
- fastapi_proxy_lib.fastapi.router: Low-level
app¶
use fastapi_proxy_lib.fastapi.app
is very convenient and out of the box, there are three helper functions:
Example:
from fastapi_proxy_lib.fastapi.app import reverse_http_app
from httpx import AsyncClient
client = AsyncClient() # (1)!
base_url = "http://www.example.com/" # (2)!
app = reverse_http_app(client=client, base_url=base_url)
- You can pass
httpx.AsyncClient
instance:- if you want to customize the arguments, e.g.
httpx.AsyncClient(proxies={})
- if you want to reuse the connection pool of
httpx.AsyncClient
Or you can pass
None
(The default value), thenfastapi-proxy-lib
will create a newhttpx.AsyncClient
instance for you. - if you want to customize the arguments, e.g.
-
Note
Thebase_url
must end with/
!
For other app helpers, please refer to their API references.
router¶
For the following scenarios, you might prefer fastapi_proxy_lib.fastapi.router:
- When you need to adjust the
app
/router
parameters. - When you need to mount the proxy on a route of larger app.
Please refer to the documentation of RouterHelper
for more information .