REST API versioning strategies: URL, header or date-based

Django Interview Q&A November 13, 2026 python

URL (/api/v1/): visible, simple, easy for routing and caching.

python
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
# ======================================================================
# Q: What are the API versioning strategies? Which one do you pick and why?
#
# URL (/api/v1/): visible, simple, easy for routing and caching. Header/media
# type (Accept: application/vnd.x.v2+json): "cleaner" REST, but harder to debug.
# Date-based (like Stripe): each account is pinned to a version. For B2B
# customers I choose URL versioning. I release a new version only for breaking
# changes. Adding fields is not breaking. I announce deprecation with headers
# (Deprecation, Sunset), track which clients still call the old version, and
# allow time for migration.
# ======================================================================

REST_FRAMEWORK = {
    'DEFAULT_VERSIONING_CLASS': 'rest_framework.versioning.URLPathVersioning',
    'ALLOWED_VERSIONS': ['v1', 'v2'], 'DEFAULT_VERSION': 'v1',
}
# in the view
def get_serializer_class(self):
    return OrderV2Serializer if self.request.version == 'v2' else OrderV1Serializer