Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to control versioning in Django Rest Framework (DRF)

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')),
like image 597
Sanjay Sikdar Avatar asked Oct 19 '25 23:10

Sanjay Sikdar


1 Answers

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.

like image 163
Felix Eklöf Avatar answered Oct 21 '25 15:10

Felix Eklöf



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!