MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
API Versioning Strategies0%
Study Materials
REST API Development with DjangoProgress 0%
1.1REST Principles1.2HTTP Methods Overview1.3Status Codes
7.1API Versioning Strategies7.2Rate Limiting & Throttling7.3Best Practices
HomeTutorialsREST API Development with DjangoAPI Versioning Strategies
Rate Limiting & Throttling

API Versioning Strategies

Beginner12 min read•Updated: 2026-11-18•By Er. Sumit Kumar (MSK Institute)
Study MaterialsCheatsheet

APIs are contracts with client applications. As business requirements change, you will inevitably introduce breaking changes—modifying field names, altering response shapes, or removing deprecated endpoints. Without API Versioning, releasing breaking changes breaks legacy mobile apps and third-party integrations. Django REST Framework provides five built-in versioning schemes to manage API evolution gracefully.


1. The Five DRF Versioning Schemes

11. URLPathVersioning (Industry Standard):
2 https://api.enterprise.com/v1/articles/
3 https://api.enterprise.com/v2/articles/
4 
52. NamespaceVersioning:
6 Routed via Django URLconf namespaces ('v1:articles', 'v2:articles')
7 
83. QueryParameterVersioning:
9 https://api.enterprise.com/articles/?version=v2
10 
114. AcceptHeaderVersioning:
12 GET /articles/ Header: Accept: application/json; version=2.0
13 
145. HostNameVersioning:
15 https://v1.api.enterprise.com/articles/
16 https://v2.api.enterprise.com/articles/

2. Configuring URLPathVersioning (Recommended)

URLPathVersioning is the most popular, explicit, and cache-friendly versioning pattern in enterprise software:

1# config/settings.py
2REST_FRAMEWORK = {
3 # 1. Declare versioning scheme
4 "DEFAULT_VERSIONING_CLASS": "rest_framework.versioning.URLPathVersioning",
5 # 2. Default fallback version if unspecified
6 "DEFAULT_VERSION": "v1",
7 # 3. Whitelist permitted versions
8 "ALLOWED_VERSIONS": ["v1", "v2"],
9 # 4. URL parameter name
10 "VERSION_PARAM": "version",
11}

3. Configuring urls.py with Version Parameter

Use the <version> path parameter in root routing:

1# config/urls.py
2from django.urls import path, re_path, include
3 
4urlpatterns = [
5 # Captures /api/v1/ or /api/v2/ into request.version
6 re_path(r"^api/(?P<version>(v1|v2))/", include("api.urls")),
7]

4. Adapting Views & Serializers Based on Version

In your views and serializers, inspect request.version to alter behavior dynamically:

1# api/views.py
2from rest_framework.viewsets import ModelViewSet
3from .models import Article
4from .serializers_v1 import ArticleSerializerV1
5from .serializers_v2 import ArticleSerializerV2
6 
7class ArticleViewSet(ModelViewSet):
8 queryset = Article.objects.all()
9 
10 def get_serializer_class(self):
11 # Serve different serializer schemas based on API version!
12 if self.request.version == "v2":
13 return ArticleSerializerV2
14 return ArticleSerializerV1

Serializer Schema Evolution:

  • v1 Response: Returns flat attributes: {"author_name": "Dr. Sumit"}.
  • v2 Response: Returns structured nested object: {"author": {"id": 1, "name": "Dr. Sumit", "avatar": "..."}}.

5. Deprecation Policy & Sunset Headers

When retiring an API version, inform clients ahead of time using the standard HTTP Sunset header:

1# In v1 middleware or response hook:
2response["Sunset"] = "Wed, 01 Jan 2027 00:00:00 GMT"
3response["Link"] = '<https://api.enterprise.com/docs/v2-migration>; rel="sunset"'

Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
What is the primary purpose of versioning a REST API?
Question 2
Why is URLPathVersioning (e.g. /api/v1/resource/) widely preferred over Header or Query Parameter versioning?
Question 3
How does a DRF view access the active requested API version string?
Question 4
What does ALLOWED_VERSIONS = ["v1", "v2"] configure in DRF settings?
Question 5
What standard HTTP response header communicates the scheduled retirement date of an older API version?
Next Lesson

Rate Limiting & Throttling

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
Handling Related ObjectsRate Limiting & Throttling

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master REST API Development with Django with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext