Every time the team needed to integrate a new external API, someone wrote custom code from scratch. No shared patterns, no consistent error handling, no retry logic. Integrations worked fine in happy-path testing and broke unpredictably in production.
Designed failure scenarios first, not success cases.
Flask-based integration layer acting as a standardized adapter between internal systems and external APIs. Unified request handler managing authentication, timeout configuration, and logging consistently across all integrations.
class APIAdapter:
def __init__(self, config: APIConfig):
self.base_url = config.base_url
self.auth = AuthModule(config.auth_type)
self.timeout = config.timeout_seconds
self.retry = RetryModule(
max_attempts=3,
backoff='exponential'
)
def request(self, method, endpoint, **kwargs):
return self.retry.execute(
fn=self._make_request,
method=method,
endpoint=endpoint,
headers=self.auth.get_headers(),
timeout=self.timeout,
**kwargs
)
def _make_request(self, **kwargs):
response = requests.request(**kwargs)
return self.normalizer.normalize(response)Handles both JSON and XML response formats and converts them to a standard internal schema. Integration logic itself never has to worry about response format parsing.
Every integration answers: what happens when the external API is slow? What when it returns 500? What when it returns malformed response? Those failure paths were designed upfront, not discovered in production.
class RetryModule:
def execute(self, fn, max_attempts=3, **kwargs):
for attempt in range(max_attempts):
try:
return fn(**kwargs)
except Timeout:
wait = 2 ** attempt # exponential
if attempt < max_attempts - 1:
time.sleep(wait)
continue
raise APITimeoutError()
except HTTPError as e:
if e.status_code in [429, 503]:
# Retryable
time.sleep(2 ** attempt)
continue
raise # Non-retryable, fail fastNew API integrations went from multi-day efforts to hours. Reliable from day one because they inherit all error handling from the framework.
"Write error handling once. Every integration inherits it. That is what a framework is for."