Overview
Bulk operations allow you to retrieve multiple resources in a single API request, reducing the number of HTTP calls and improving performance. Currently, only the kits resource supports bulk operations.Kits Bulk Endpoint
GET /api/kits/bulk
Implementation:fkapi/api.py:1312-1407
Retrieve multiple kits by their slugs or URLs in a single request.
Parameters
Constraints
- Minimum: 2 kits
- Maximum: 30 kits
- Slugs must be comma-separated
- Accepts both slugs and full URLs
Request Examples
Using slugs:Response Format
The bulk endpoint returns a reduced response format optimized for performance, containing only essential fields:Response Schema
KitBulkSchema (reduced format):
ClubBulkSchema:
SeasonBulkSchema:
BrandBulkSchema:
Implementation Details
URL Slug Extraction (fkapi/api.py:1288-1310):
The endpoint automatically extracts slugs from full URLs:
fkapi/api.py:1334-1407):
- Parse input: Split comma-separated slugs
- Clean slugs: Strip whitespace and extract from URLs
- Validate count: Ensure 2-30 kits
- Check cache: Look for cached results
- Fetch kits: Query database with
slug__in=slug_list - Build response: Map kits to slugs in original order
- Cache results: Store for 30 minutes
Response Order
Results are returned in the same order as the input slugs, not database order. Example:Validation Errors
Too few kits:Caching
Cache Key Generation:- TTL: 30 minutes (
CACHE_TIMEOUT_MEDIUM) - Backend: Redis
- Key format:
fkapi:kits_bulk_{sorted_slugs_hash}
Use Cases
User Collection Display
Fetch multiple kits for a user’s collection page:Comparison View
Load multiple kits for side-by-side comparison:Batch Updates
Fetch kit details before performing batch operations:Related Kits Widget
Show related kits (same team, different seasons):Performance Benefits
Network Efficiency
Without bulk endpoint (10 kits):- 10 separate HTTP requests
- 10 × connection overhead
- ~10 × latency
- 1 HTTP request
- 1 × connection overhead
- 1 × latency
Database Optimization
Bulk operations use a single optimized query:Cache Efficiency
- One cache lookup instead of multiple
- Reduced Redis connections
- Lower cache key overhead
Comparison: Bulk vs Individual
Individual Kit Endpoint
GET /api/kits/ Response includes:- Complete kit details (ID, name, slug)
- Full team information (ID, name, slug, logos, country)
- Complete season details (ID, year, first_year, second_year)
- Full competition list
- Detailed kit type (category, order, goalkeeper flag)
- Complete brand information
- Design and color details
- Image URLs
- Ratings and additional metadata
- Single kit detail page
- Need complete information
- Need competition details
- Need color/design analysis
Bulk Kit Endpoint
GET /api/kits/bulk?slugs=… Response includes:- Kit name
- Team name and logos
- Season year only
- Brand name and logos
- Main image URL
- Multiple kits at once
- Collection/gallery views
- List/preview displays
- Performance-critical scenarios
Future Enhancements
These features are not currently implemented but may be added in future versions:
Brands Bulk Endpoint
Competitions Bulk Endpoint
Advanced Bulk Options
Proposed query parameters:fields- Select specific fields to returninclude- Include related resourcesformat- Response format (compact/full)
Error Handling
Missing Kits
If some slugs don’t exist, they’re silently skipped:Invalid Input
Empty slugs:Best Practices
Optimal Batch Size
- Recommended: 5-15 kits per request
- Maximum: 30 kits
- Avoid: Requesting 2-3 kits (minimal benefit)
Slug Management
Clean slugs before sending:Error Handling
Fallback Strategy
Related Documentation
- Search Functionality - Find kits before fetching in bulk
- Caching Strategy - How bulk results are cached
- API Overview - Complete endpoint documentation