diff --git a/src/fastapi_app/lib/api/v1/handlers/__init__.py b/src/fastapi_app/lib/api/v1/handlers/__init__.py index 4df1385..e679678 100644 --- a/src/fastapi_app/lib/api/v1/handlers/__init__.py +++ b/src/fastapi_app/lib/api/v1/handlers/__init__.py @@ -1,5 +1,5 @@ from .health import * __all__ = [ - "health_router", + "basic_router", ] diff --git a/src/fastapi_app/lib/api/v1/handlers/health/__init__.py b/src/fastapi_app/lib/api/v1/handlers/health/__init__.py index 48a8b68..34b4679 100644 --- a/src/fastapi_app/lib/api/v1/handlers/health/__init__.py +++ b/src/fastapi_app/lib/api/v1/handlers/health/__init__.py @@ -1,5 +1,5 @@ -from .liveness_probe import router as health_router +from .liveness_probe import basic_router __all__ = [ - "health_router", + "basic_router", ] diff --git a/src/fastapi_app/lib/api/v1/handlers/health/liveness_probe.py b/src/fastapi_app/lib/api/v1/handlers/health/liveness_probe.py index d3fbbce..93465b7 100644 --- a/src/fastapi_app/lib/api/v1/handlers/health/liveness_probe.py +++ b/src/fastapi_app/lib/api/v1/handlers/health/liveness_probe.py @@ -2,10 +2,10 @@ import lib.api.v1.schemas as api_shemas -router = fastapi.APIRouter() +basic_router = fastapi.APIRouter() -@router.get( +@basic_router.get( "/", response_model=api_shemas.HealthResponseModel, summary="Статус работоспособности", diff --git a/src/fastapi_app/lib/app/app.py b/src/fastapi_app/lib/app/app.py index 3443f7c..f20bb8d 100644 --- a/src/fastapi_app/lib/app/app.py +++ b/src/fastapi_app/lib/app/app.py @@ -45,6 +45,7 @@ def from_settings(cls, settings: app_settings.Settings) -> typing.Self: logger.info("Initializing global clients") postgres_client = clients.AsyncPostgresClient(settings=settings) + http_client = clients.get_async_http_session() disposable_resources.append( DisposableResource( @@ -72,10 +73,10 @@ def from_settings(cls, settings: app_settings.Settings) -> typing.Self: # Handlers logger.info("Initializing handlers") - # liveness_probe_handler = health_handlers.LivenessProbeHandler() + liveness_probe_handler = api_v1_handlers.basic_router + logger.info("Creating application") - # aio_app = aiohttp_web.Application() fastapi_app = fastapi.FastAPI( title=settings.app.title, @@ -86,7 +87,7 @@ def from_settings(cls, settings: app_settings.Settings) -> typing.Self: ) # Routes - fastapi_app.include_router(api_v1_handlers.health_router, prefix="/api/v1/health", tags=["health"]) + fastapi_app.include_router(liveness_probe_handler, prefix="/api/v1/health", tags=["health"]) application = Application( settings=settings, diff --git a/src/fastapi_app/lib/clients/__init__.py b/src/fastapi_app/lib/clients/__init__.py index 1fbe64c..40d0e2f 100644 --- a/src/fastapi_app/lib/clients/__init__.py +++ b/src/fastapi_app/lib/clients/__init__.py @@ -1,3 +1,4 @@ +from .httpx import get_async_http_session from .postgres import AsyncPostgresClient -__all__ = ["AsyncPostgresClient"] +__all__ = ["AsyncPostgresClient", "get_async_http_session"] diff --git a/src/fastapi_app/lib/clients/httpx.py b/src/fastapi_app/lib/clients/httpx.py index 4d0b672..5570d2c 100644 --- a/src/fastapi_app/lib/clients/httpx.py +++ b/src/fastapi_app/lib/clients/httpx.py @@ -1,4 +1,3 @@ -# Purpose: Provide an example of an async http client for the application import contextlib import typing @@ -6,7 +5,12 @@ @contextlib.asynccontextmanager -async def get_http_client() -> typing.AsyncGenerator[httpx.AsyncClient, None]: - client = httpx.AsyncClient() # Insert your own settings here +async def get_async_http_session( + settings: dict[str, typing.Any] | None = None +) -> typing.AsyncGenerator[httpx.AsyncClient, None]: + """Async http client.""" + if settings is None: + settings = {} + client = httpx.AsyncClient(**settings) # Insert your own settings here async with client as ac: yield ac