Files
Backend/external_api_adapter
2026-04-10 16:12:51 +03:30
..
2026-04-10 16:12:51 +03:30
2026-03-25 00:51:04 +03:30
2026-03-25 16:19:28 +03:30
2026-03-25 00:51:04 +03:30
2026-03-25 00:51:04 +03:30
2026-03-29 13:40:23 +03:30
2026-04-02 23:25:39 +03:30
2026-03-25 00:51:04 +03:30

External API Adapter

Settings

USE_EXTERNAL_API_MOCK = os.getenv("USE_EXTERNAL_API_MOCK", "false").lower() == "true"

EXTERNAL_SERVICES = {
    "ai": {
        "base_url": os.getenv("AI_SERVICE_BASE_URL", ""),
        "api_key": os.getenv("AI_SERVICE_API_KEY", ""),
    },
    "farm_hub": {
        "base_url": os.getenv("FARM_HUB_SERVICE_BASE_URL", ""),
        "api_key": os.getenv("FARM_HUB_SERVICE_API_KEY", ""),
    },
}

Usage

from rest_framework.response import Response
from rest_framework.views import APIView

from external_api_adapter import request


class PredictionProxyView(APIView):
    def get(self, request_obj):
        adapter_response = request("ai", "/predict")
        return Response(adapter_response.data, status=adapter_response.status_code)