rest_framework.versioning

Module Contents

class BaseVersioning

Bases:object

default_version
allowed_versions
version_param
determine_version(self, request, *args, **kwargs)
reverse(self, viewname, args=None, kwargs=None, request=None, format=None, **extra)
is_allowed_version(self, version)
class AcceptHeaderVersioning

Bases:rest_framework.versioning.BaseVersioning

GET /something/ HTTP/1.1 Host: example.com Accept: application/json; version=1.0

invalid_version_message
determine_version(self, request, *args, **kwargs)
class URLPathVersioning

Bases:rest_framework.versioning.BaseVersioning

To the client this is the same style as NamespaceVersioning. The difference is in the backend - this implementation uses Django’s URL keyword arguments to determine the version.

An example URL conf for two views that accept two different versions.

urlpatterns = [
url(r’^(?P<version>[v1|v2]+)/users/$’, users_list, name=’users-list’), url(r’^(?P<version>[v1|v2]+)/users/(?P<pk>[0-9]+)/$’, users_detail, name=’users-detail’)

]

GET /1.0/something/ HTTP/1.1 Host: example.com Accept: application/json

invalid_version_message
determine_version(self, request, *args, **kwargs)
reverse(self, viewname, args=None, kwargs=None, request=None, format=None, **extra)
class NamespaceVersioning

Bases:rest_framework.versioning.BaseVersioning

To the client this is the same style as URLPathVersioning. The difference is in the backend - this implementation uses Django’s URL namespaces to determine the version.

An example URL conf that is namespaced into two separate versions

# users/urls.py urlpatterns = [

url(r’^/users/$’, users_list, name=’users-list’), url(r’^/users/(?P<pk>[0-9]+)/$’, users_detail, name=’users-detail’)

]

# urls.py urlpatterns = [

url(r’^v1/’, include(‘users.urls’, namespace=’v1’)), url(r’^v2/’, include(‘users.urls’, namespace=’v2’))

]

GET /1.0/something/ HTTP/1.1 Host: example.com Accept: application/json

invalid_version_message
determine_version(self, request, *args, **kwargs)
reverse(self, viewname, args=None, kwargs=None, request=None, format=None, **extra)
get_versioned_viewname(self, viewname, request)
class HostNameVersioning

Bases:rest_framework.versioning.BaseVersioning

GET /something/ HTTP/1.1 Host: v1.example.com Accept: application/json

hostname_regex
invalid_version_message
determine_version(self, request, *args, **kwargs)
class QueryParameterVersioning

Bases:rest_framework.versioning.BaseVersioning

GET /something/?version=0.1 HTTP/1.1 Host: example.com Accept: application/json

invalid_version_message
determine_version(self, request, *args, **kwargs)
reverse(self, viewname, args=None, kwargs=None, request=None, format=None, **extra)