HackSoftware / Django-Styleguide

Django styleguide used in HackSoft projects

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to handle api versioning?

akhil023 opened this issue · comments

Thanks for the styleguide. But I could not find any mention of how to handle api vesioning.

@akhil023 hello 👋

For API versioning, it's basically "choose your own adventure".

You can go with the DRF approach - https://www.django-rest-framework.org/api-guide/versioning/

What we usually do is the following:

  • We have a generic api django app, that holds ulrs.py, that looks like this:
from django.urls import path, include

v1_patterns = [
   ...
]

urlpatterns = [path("v1/", include((v1_patterns, "v1")))]

And now, in each app, urls.py is a folder-module with ulrs/v1.py inside, for example. And then we refer to those v1 urls.

What we try to avoid is having 1 API that if-checks depending on version & then decides what to do.

We prefer splitting by modules & actually isolating different versions from each other.

At some point, we might add this approach, with better examples, to the styleguide.

Hopefully this is useful ✌️