Skip to main content

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.
Note: Bulk endpoints for brands and competitions are not currently implemented. Only /api/kits/bulk is available.

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:
Using URLs:
Mixed (slugs and URLs):

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:
Processing Flow (fkapi/api.py:1334-1407):
  1. Parse input: Split comma-separated slugs
  2. Clean slugs: Strip whitespace and extract from URLs
  3. Validate count: Ensure 2-30 kits
  4. Check cache: Look for cached results
  5. Fetch kits: Query database with slug__in=slug_list
  6. Build response: Map kits to slugs in original order
  7. Cache results: Store for 30 minutes
Query Optimization:

Response Order

Results are returned in the same order as the input slugs, not database order. Example:
If a slug is not found, it’s skipped (no error, no placeholder).

Validation Errors

Too few kits:
HTTP 400 Bad Request Too many kits:
HTTP 400 Bad Request

Caching

Cache Key Generation:
Cache Settings:
  • TTL: 30 minutes (CACHE_TIMEOUT_MEDIUM)
  • Backend: Redis
  • Key format: fkapi:kits_bulk_{sorted_slugs_hash}
Cache invalidation: When any Kit model is saved/deleted

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:
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
With bulk endpoint (10 kits):
  • 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
When to use:
  • 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
When to use:
  • 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

Expected response:

Competitions Bulk Endpoint

Expected response:

Advanced Bulk Options

Proposed query parameters:
  • fields - Select specific fields to return
  • include - Include related resources
  • format - Response format (compact/full)
Example:

Error Handling

Missing Kits

If some slugs don’t exist, they’re silently skipped:

Invalid Input

Empty slugs:
Single kit:
Too many kits:

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