How to control versioning in Django Rest Framework (DRF)

2.4k views Asked by At

I want to know what is the best practices for controlling the Version for Mobile App APIs.

Requirement

  • If I change something in my database previous version of the app should not be affected.
  • Currently I'm doing like...
path('v1/auth/', include('authentication.urls')),
path('v2/auth/', include('authentication.urls2')), # Example
path('v1/api/', include('contentstudio.urls')),
1

There are 1 answers

0
Felix Eklöf On BEST ANSWER

Django REST Framework has support for many different methods of versioning you api. Check out the docs to find which one suits you best.

According to the docs, the AcceptHeaderVersioning method "is generally considered as best practice". ie. you put the version in the Accept header like so:

Accept: application/json; version=1.0

Using any of these methods you will have access to request.version in your views to determine the behavior of the different versions.