From 8f2065e31f14f3738b2853bdbed9c4859431260a Mon Sep 17 00:00:00 2001 From: Artem Litvinov Date: Sat, 30 Sep 2023 21:34:42 +0100 Subject: [PATCH] feat: example of httpx async client --- src/fastapi_app/lib/clients/httpx.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/fastapi_app/lib/clients/httpx.py diff --git a/src/fastapi_app/lib/clients/httpx.py b/src/fastapi_app/lib/clients/httpx.py new file mode 100644 index 0000000..4d0b672 --- /dev/null +++ b/src/fastapi_app/lib/clients/httpx.py @@ -0,0 +1,12 @@ +# Purpose: Provide an example of an async http client for the application +import contextlib +import typing + +import httpx + + +@contextlib.asynccontextmanager +async def get_http_client() -> typing.AsyncGenerator[httpx.AsyncClient, None]: + client = httpx.AsyncClient() # Insert your own settings here + async with client as ac: + yield ac