Skip to main content

What is FKAPI?

FKAPI (Football Kit Archive API) is the backend service that powers FootyCollect’s kit search and metadata functionality. It provides access to the extensive Football Kit Archive database, enabling users to search for kits by club, season, competition, and automatically populate collection data.
FKAPI is an optional but core component for the intended FootyCollect workflow. Without FKAPI, you can still manage items manually, but you won’t have access to the search-and-add flow or bulk imports from the archive.

Why FootyCollect Integrates with FKAPI

FootyCollect uses FKAPI as the primary source for kit metadata when adding items to your collection:
  • Search by club, season, and competition: Find kits quickly without manual data entry
  • Pre-filled metadata: Automatically populate colors, designs, competitions, and logos
  • Bulk imports: Import entire user collections from the Football Kit Archive
  • Logo downloads: Automatically fetch club and brand logos for visual identification
Without FKAPI running, FootyCollect operates in manual mode where you enter all item details yourself. With FKAPI deployed alongside FootyCollect, you unlock the full search-and-add experience.

Architecture

FKAPIClient

The FKAPIClient class (footycollect/api/client.py) is the main interface for all FKAPI communication. It provides:
  • Caching layer: 1-hour cache by default to reduce API load
  • Circuit breaker pattern: Prevents cascading failures
  • Rate limiting: Maximum 100 requests per minute
  • Retry logic: Automatic retries with exponential backoff (max 3 attempts)
  • Request timeout: 60 seconds per request

Circuit Breaker Pattern

FootyCollect implements a circuit breaker to protect against FKAPI failures:
How it works:
  1. Closed state: Normal operation, all requests proceed
  2. Open state: After 5 consecutive failures, circuit opens and blocks requests
  3. Half-open state: After 60 seconds, circuit allows one test request
  4. Recovery: If test request succeeds, circuit closes and normal operation resumes
When the circuit breaker is open, FKAPI requests will fail immediately and return cached data if available. This prevents overwhelming a failing API with more requests.

Caching Strategy

The client uses Django’s cache backend (Redis in production) with intelligent fallback:

Cache Key Generation

Cache keys are generated using SHA-256 hash of endpoint and parameters:

Stale Cache Fallback

When FKAPI is unavailable (circuit breaker open or timeout), the client attempts to return stale cached data:
This ensures FootyCollect remains functional even when FKAPI is down.

Rate Limiting

FKAPI client enforces rate limiting to prevent API abuse:
  • Limit: 100 requests per minute
  • Window: 60 seconds
  • Storage: Redis cache with automatic expiration
When rate limit is exceeded, requests return cached data if available.

Proxy Endpoints

FootyCollect provides proxy endpoints at /fkapi/ that wrap the FKAPI client and add additional functionality: All proxy endpoints include:
  • Rate limiting: 100 requests per hour per IP
  • Authentication: User must be authenticated
  • Error handling: Returns 503 when FKAPI is unavailable
Proxy endpoints are defined in footycollect/api/urls.py and implemented in footycollect/api/views.py.

Error Handling

The client implements comprehensive error handling:

Timeout Errors

HTTP Errors

HTTP errors are logged and retried automatically with exponential backoff:

JSON Decode Errors

JSON errors stop retries immediately since they indicate a client-side issue:

Configuration

Required environment variables:
string
required
The IP address or hostname of your FKAPI instance (without http://)Example: fkapi.example.com or 192.168.1.100:8000
string
required
API key for authenticating with FKAPISet this in your FKAPI instance configuration

Example Configuration

Client Initialization

Best Practices

Always handle None returns: FKAPI methods return None when the API is unavailable. Your code should gracefully handle this:
Use caching wisely: Most endpoints cache by default. Disable caching only when you need fresh data:

Next Steps