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
Architecture
FKAPIClient
TheFKAPIClient 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:- Closed state: Normal operation, all requests proceed
- Open state: After 5 consecutive failures, circuit opens and blocks requests
- Half-open state: After 60 seconds, circuit allows one test request
- Recovery: If test request succeeds, circuit closes and normal operation resumes
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: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
Proxy Endpoints
FootyCollect provides proxy endpoints at/fkapi/ that wrap the FKAPI client and add additional functionality:
| Endpoint | FKAPI Method | Description |
|---|---|---|
/fkapi/clubs/search/ | search_clubs() | Search clubs by keyword |
/fkapi/kits/search/ | search_kits() | Search kits by keyword |
/fkapi/kit/<id>/ | get_kit_details() | Get complete kit details |
/fkapi/clubs/<id>/seasons/ | get_club_seasons() | Get seasons for a club |
/fkapi/clubs/<id>/seasons/<season_id>/kits/ | get_club_kits() | Get kits for club/season |
/fkapi/brands/search/ | search_brands() | Search brands by keyword |
/fkapi/competitions/search/ | search_competitions() | Search competitions by keyword |
- 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:The IP address or hostname of your FKAPI instance (without http://)Example:
fkapi.example.com or 192.168.1.100:8000API key for authenticating with FKAPISet this in your FKAPI instance configuration
Example Configuration
Client Initialization
Best Practices
Use caching wisely: Most endpoints cache by default. Disable caching only when you need fresh data:
Next Steps
- Learn about searching kits via FKAPI
- Explore bulk operations for importing collections
- Review the proxy endpoints for frontend integration