Menu

How to support v1 and v2 endpoints in a Django REST API
📰

How to support v1 and v2 endpoints in a Django REST API

DEV Community: django·Mojtaba Arvin·3 days ago
#RlS2ftnI
#devtodjango#devto#dev#version#endpoint
Long article (1915 words) — no AI summary yet.
Reading 0:00
15s threshold

Learn how to register versioned DRF endpoints declaratively and compare the approach with explicit Django URL routing.

Package disclosure: The author is the creator, owner, and maintainer of django-api-versioning .

When an API evolves, existing clients may need to continue using /api/v1/ while newer clients use /api/v2/ . The challenge is deciding which implementation serves each version and maintaining the corresponding URL routes.

Django API Versioning provides declarative endpoint registration for Django and Django REST Framework (DRF). Instead of writing a separate path() declaration for every version, you define endpoint availability alongside the view implementation.

This article demonstrates the package's approach and compares it with explicit Django URL routing. The examples use integer version identifiers such as 1 and 2 ; the default URL configuration renders them as v1 and v2 .

1. Declarative versioned endpoints

Consider an API that exposes a list and detail endpoint for books.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.