django-api-versioning 0.1.3__tar.gz → 0.1.4__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- {django-api-versioning-0.1.3/django_api_versioning.egg-info → django-api-versioning-0.1.4}/PKG-INFO +61 -13
- {django-api-versioning-0.1.3 → django-api-versioning-0.1.4}/README.md +60 -12
- {django-api-versioning-0.1.3 → django-api-versioning-0.1.4/django_api_versioning.egg-info}/PKG-INFO +61 -13
- {django-api-versioning-0.1.3 → django-api-versioning-0.1.4}/setup.py +1 -1
- {django-api-versioning-0.1.3 → django-api-versioning-0.1.4}/.pre-commit-config.yaml +0 -0
- {django-api-versioning-0.1.3 → django-api-versioning-0.1.4}/LICENSE +0 -0
- {django-api-versioning-0.1.3 → django-api-versioning-0.1.4}/MANIFEST.in +0 -0
- {django-api-versioning-0.1.3 → django-api-versioning-0.1.4}/django_api_versioning/__init__.py +0 -0
- {django-api-versioning-0.1.3 → django-api-versioning-0.1.4}/django_api_versioning/decorators.py +0 -0
- {django-api-versioning-0.1.3 → django-api-versioning-0.1.4}/django_api_versioning/exceptions.py +0 -0
- {django-api-versioning-0.1.3 → django-api-versioning-0.1.4}/django_api_versioning/registry.py +0 -0
- {django-api-versioning-0.1.3 → django-api-versioning-0.1.4}/django_api_versioning/settings.py +0 -0
- {django-api-versioning-0.1.3 → django-api-versioning-0.1.4}/django_api_versioning/urls.py +0 -0
- {django-api-versioning-0.1.3 → django-api-versioning-0.1.4}/django_api_versioning.egg-info/SOURCES.txt +0 -0
- {django-api-versioning-0.1.3 → django-api-versioning-0.1.4}/django_api_versioning.egg-info/dependency_links.txt +0 -0
- {django-api-versioning-0.1.3 → django-api-versioning-0.1.4}/django_api_versioning.egg-info/requires.txt +0 -0
- {django-api-versioning-0.1.3 → django-api-versioning-0.1.4}/django_api_versioning.egg-info/top_level.txt +0 -0
- {django-api-versioning-0.1.3 → django-api-versioning-0.1.4}/pyproject.toml +0 -0
- {django-api-versioning-0.1.3 → django-api-versioning-0.1.4}/pytest.ini +0 -0
- {django-api-versioning-0.1.3 → django-api-versioning-0.1.4}/requirements-dev.txt +0 -0
- {django-api-versioning-0.1.3 → django-api-versioning-0.1.4}/requirements.txt +0 -0
- {django-api-versioning-0.1.3 → django-api-versioning-0.1.4}/setup.cfg +0 -0
- {django-api-versioning-0.1.3 → django-api-versioning-0.1.4}/tests/__init__.py +0 -0
- {django-api-versioning-0.1.3 → django-api-versioning-0.1.4}/tests/test_decorators.py +0 -0
- {django-api-versioning-0.1.3 → django-api-versioning-0.1.4}/tests/test_exceptions.py +0 -0
- {django-api-versioning-0.1.3 → django-api-versioning-0.1.4}/tests/test_registry.py +0 -0
- {django-api-versioning-0.1.3 → django-api-versioning-0.1.4}/tests/test_settings.py +0 -0
- {django-api-versioning-0.1.3 → django-api-versioning-0.1.4}/tests/test_urls.py +0 -0
{django-api-versioning-0.1.3/django_api_versioning.egg-info → django-api-versioning-0.1.4}/PKG-INFO
RENAMED
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: django-api-versioning
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.4
|
4
4
|
Summary: Django API versioning decorator provides a solution for managing multiple API versions within the Django framework, enabling versioning through URLs with backward compatibility and automatically registering routes.
|
5
5
|
Home-page: https://github.com/mojtaba-arvin/django-api-versioning
|
6
6
|
Author: Mojtaba Arvin
|
@@ -107,6 +107,11 @@ def users_view(request):
|
|
107
107
|
|
108
108
|
In this example, the `users_view` function is decorated with the endpoint decorator. This specifies that the view is accessible under version `2` of the API and **supports backward compatibility**. The `backward=True` flag as default ensures that users can also access the previous version (version `1`) at `/api/v1/account_app/users`.
|
109
109
|
|
110
|
+
```bash
|
111
|
+
api/v1/account_app/users [name='users_list_api']
|
112
|
+
api/v2/account_app/users [name='users_list_api']
|
113
|
+
```
|
114
|
+
|
110
115
|
#### Example for Class-Based Views (CBVs):
|
111
116
|
|
112
117
|
For class-based views, you can apply the decorator to methods such as `get`, `post`, or any other HTTP method you need to handle. Here’s an example:
|
@@ -131,11 +136,13 @@ If you have already installed [Django Rest Framework](https://www.django-rest-fr
|
|
131
136
|
|
132
137
|
```python
|
133
138
|
from rest_framework.views import APIView
|
139
|
+
from rest_framework.permissions import AllowAny
|
134
140
|
from rest_framework.response import Response
|
135
141
|
from django_api_versioning.decorators import endpoint
|
136
142
|
|
137
143
|
@endpoint("users", version=2, app_name='account_app', view_name="users_list_api")
|
138
144
|
class UsersAPIView(APIView):
|
145
|
+
permission_classes = [AllowAny]
|
139
146
|
|
140
147
|
def get(self, request):
|
141
148
|
return Response({"message": "API Version 2 Users"})
|
@@ -143,10 +150,12 @@ class UsersAPIView(APIView):
|
|
143
150
|
|
144
151
|
#### URL Generation Based on Versioning:
|
145
152
|
|
146
|
-
Once the decorator is applied, the URLs for your API will be generated based on the version specified in the decorator. For example, if the `API_MIN_VERSION` in your settings.py is set to `1` and the version in the decorator is set to `2`, the following URLs will be available:
|
153
|
+
Once the decorator is applied, the URLs for your API will be generated based on the version specified in the decorator. For example, if the `API_MIN_VERSION` in your `settings.py` is set to `1` and the version in the decorator is set to `2`, the following URLs will be available:
|
147
154
|
|
148
|
-
|
149
|
-
|
155
|
+
```bash
|
156
|
+
api/v1/account_app/users [name='users_list_api']
|
157
|
+
api/v2/account_app/users [name='users_list_api']
|
158
|
+
```
|
150
159
|
|
151
160
|
The `API_MIN_VERSION` setting ensures that users can access the API using different versions, providing backward compatibility. You can adjust which versions are considered valid by modifying the `API_MIN_VERSION` and `version` numbers in the decorators.
|
152
161
|
|
@@ -160,8 +169,10 @@ The `API_MIN_VERSION` setting ensures that users can access the API using differ
|
|
160
169
|
|
161
170
|
The generated URLs will be:
|
162
171
|
|
163
|
-
|
164
|
-
|
172
|
+
```bash
|
173
|
+
api/v1/users [name='users_list_api']
|
174
|
+
api/v2/users [name='users_list_api']
|
175
|
+
```
|
165
176
|
|
166
177
|
**Without `version`:** If you don't pass `version` in the decorator, like this:
|
167
178
|
|
@@ -171,7 +182,9 @@ The generated URLs will be:
|
|
171
182
|
|
172
183
|
API versioning will be disabled (`API_BASE_PATH` as prefix will be removed) for that view. The only URL generated will be:
|
173
184
|
|
174
|
-
|
185
|
+
```bash
|
186
|
+
users [name='users_list_api']
|
187
|
+
```
|
175
188
|
|
176
189
|
**Setting `backward=False`:** By default, the `backward` parameter is set to `True`, which ensures backward compatibility. If you explicitly set `backward=False`, like this:
|
177
190
|
|
@@ -181,7 +194,9 @@ API versioning will be disabled (`API_BASE_PATH` as prefix will be removed) for
|
|
181
194
|
|
182
195
|
The generated URL will be only version 2:
|
183
196
|
|
184
|
-
|
197
|
+
```bash
|
198
|
+
api/v2/users [name='users_list_api']
|
199
|
+
```
|
185
200
|
|
186
201
|
4. Run the Server:
|
187
202
|
|
@@ -191,23 +206,56 @@ python manage.py runserver
|
|
191
206
|
|
192
207
|
## Notes
|
193
208
|
|
194
|
-
|
209
|
+
#### 1. `API_BASE_PATH` in settings Must Include `{version}`:
|
195
210
|
|
196
211
|
The `API_BASE_PATH` should always include `{version}` to ensure proper API versioning. This is important for correctly mapping API routes to different versions.
|
197
212
|
|
198
|
-
|
213
|
+
#### 2. Using `app_name` in the `endpoint` decorator:
|
199
214
|
|
200
215
|
It's recommended to fill in the `app_name` in the `endpoint` decorator to make the API URLs **more unique and organized**. This ensures that the routes are scoped under the correct app, avoiding potential conflicts and making them easier to manage.
|
201
216
|
|
202
|
-
|
217
|
+
#### 3. Behavior When Resolving a Route:
|
218
|
+
|
219
|
+
When resolving the route using Django's `reverse()` function or any other method to resolve the URL, the latest version (highest version number) of the API will be returned. In this example, route for version 3 would be resolved:
|
220
|
+
|
221
|
+
```python
|
222
|
+
from django_api_versioning.decorators import endpoint
|
223
|
+
from django.http import JsonResponse
|
224
|
+
from django.views import View
|
225
|
+
from django.urls import reverse
|
226
|
+
|
227
|
+
|
228
|
+
@endpoint("users", version=3, app_name='account_app', view_name="users_list_api")
|
229
|
+
class UsersView(View):
|
230
|
+
|
231
|
+
def get(self, request):
|
232
|
+
|
233
|
+
return JsonResponse({"path of users_list_api view is": reverse('users_list_api')})
|
234
|
+
```
|
235
|
+
|
236
|
+
response body:
|
237
|
+
|
238
|
+
```json
|
239
|
+
{ "path of users_list_api view is": "api/v3/account_app/users" }
|
240
|
+
```
|
241
|
+
|
242
|
+
The generated URLs will be:
|
243
|
+
|
244
|
+
```bash
|
245
|
+
api/v1/account_app/users [name='users_list_api']
|
246
|
+
api/v2/account_app/users [name='users_list_api']
|
247
|
+
api/v3/account_app/users [name='users_list_api']
|
248
|
+
```
|
249
|
+
|
250
|
+
#### 4. Views with Version Less Than `API_MIN_VERSION` Are Automatically Ignored:
|
203
251
|
|
204
252
|
Any view whose `version` is less than the `API_MIN_VERSION` will be automatically ignored. This means clients will no longer have access to these older versions, **without the need to manually edit or remove code**. This is handled automatically by the package.
|
205
253
|
|
206
|
-
|
254
|
+
#### 5. URLs for Versions Between `API_MIN_VERSION` <= `version` <= `API_MAX_VERSION`:
|
207
255
|
|
208
256
|
Endpoints that have versions within the range defined by `API_MIN_VERSION` <= `version` <= `API_MAX_VERSION` will always have a corresponding URL generated. This ensures that only valid versions will be accessible, providing flexibility in version management.
|
209
257
|
|
210
|
-
|
258
|
+
## `endpoint` Decorator Function Definition
|
211
259
|
|
212
260
|
The `endpoint` decorator is designed to register API views with versioning support in a Django application. It provides flexibility in managing versioned endpoints and ensures backward compatibility with previous versions of the API.
|
213
261
|
|
@@ -85,6 +85,11 @@ def users_view(request):
|
|
85
85
|
|
86
86
|
In this example, the `users_view` function is decorated with the endpoint decorator. This specifies that the view is accessible under version `2` of the API and **supports backward compatibility**. The `backward=True` flag as default ensures that users can also access the previous version (version `1`) at `/api/v1/account_app/users`.
|
87
87
|
|
88
|
+
```bash
|
89
|
+
api/v1/account_app/users [name='users_list_api']
|
90
|
+
api/v2/account_app/users [name='users_list_api']
|
91
|
+
```
|
92
|
+
|
88
93
|
#### Example for Class-Based Views (CBVs):
|
89
94
|
|
90
95
|
For class-based views, you can apply the decorator to methods such as `get`, `post`, or any other HTTP method you need to handle. Here’s an example:
|
@@ -109,11 +114,13 @@ If you have already installed [Django Rest Framework](https://www.django-rest-fr
|
|
109
114
|
|
110
115
|
```python
|
111
116
|
from rest_framework.views import APIView
|
117
|
+
from rest_framework.permissions import AllowAny
|
112
118
|
from rest_framework.response import Response
|
113
119
|
from django_api_versioning.decorators import endpoint
|
114
120
|
|
115
121
|
@endpoint("users", version=2, app_name='account_app', view_name="users_list_api")
|
116
122
|
class UsersAPIView(APIView):
|
123
|
+
permission_classes = [AllowAny]
|
117
124
|
|
118
125
|
def get(self, request):
|
119
126
|
return Response({"message": "API Version 2 Users"})
|
@@ -121,10 +128,12 @@ class UsersAPIView(APIView):
|
|
121
128
|
|
122
129
|
#### URL Generation Based on Versioning:
|
123
130
|
|
124
|
-
Once the decorator is applied, the URLs for your API will be generated based on the version specified in the decorator. For example, if the `API_MIN_VERSION` in your settings.py is set to `1` and the version in the decorator is set to `2`, the following URLs will be available:
|
131
|
+
Once the decorator is applied, the URLs for your API will be generated based on the version specified in the decorator. For example, if the `API_MIN_VERSION` in your `settings.py` is set to `1` and the version in the decorator is set to `2`, the following URLs will be available:
|
125
132
|
|
126
|
-
|
127
|
-
|
133
|
+
```bash
|
134
|
+
api/v1/account_app/users [name='users_list_api']
|
135
|
+
api/v2/account_app/users [name='users_list_api']
|
136
|
+
```
|
128
137
|
|
129
138
|
The `API_MIN_VERSION` setting ensures that users can access the API using different versions, providing backward compatibility. You can adjust which versions are considered valid by modifying the `API_MIN_VERSION` and `version` numbers in the decorators.
|
130
139
|
|
@@ -138,8 +147,10 @@ The `API_MIN_VERSION` setting ensures that users can access the API using differ
|
|
138
147
|
|
139
148
|
The generated URLs will be:
|
140
149
|
|
141
|
-
|
142
|
-
|
150
|
+
```bash
|
151
|
+
api/v1/users [name='users_list_api']
|
152
|
+
api/v2/users [name='users_list_api']
|
153
|
+
```
|
143
154
|
|
144
155
|
**Without `version`:** If you don't pass `version` in the decorator, like this:
|
145
156
|
|
@@ -149,7 +160,9 @@ The generated URLs will be:
|
|
149
160
|
|
150
161
|
API versioning will be disabled (`API_BASE_PATH` as prefix will be removed) for that view. The only URL generated will be:
|
151
162
|
|
152
|
-
|
163
|
+
```bash
|
164
|
+
users [name='users_list_api']
|
165
|
+
```
|
153
166
|
|
154
167
|
**Setting `backward=False`:** By default, the `backward` parameter is set to `True`, which ensures backward compatibility. If you explicitly set `backward=False`, like this:
|
155
168
|
|
@@ -159,7 +172,9 @@ API versioning will be disabled (`API_BASE_PATH` as prefix will be removed) for
|
|
159
172
|
|
160
173
|
The generated URL will be only version 2:
|
161
174
|
|
162
|
-
|
175
|
+
```bash
|
176
|
+
api/v2/users [name='users_list_api']
|
177
|
+
```
|
163
178
|
|
164
179
|
4. Run the Server:
|
165
180
|
|
@@ -169,23 +184,56 @@ python manage.py runserver
|
|
169
184
|
|
170
185
|
## Notes
|
171
186
|
|
172
|
-
|
187
|
+
#### 1. `API_BASE_PATH` in settings Must Include `{version}`:
|
173
188
|
|
174
189
|
The `API_BASE_PATH` should always include `{version}` to ensure proper API versioning. This is important for correctly mapping API routes to different versions.
|
175
190
|
|
176
|
-
|
191
|
+
#### 2. Using `app_name` in the `endpoint` decorator:
|
177
192
|
|
178
193
|
It's recommended to fill in the `app_name` in the `endpoint` decorator to make the API URLs **more unique and organized**. This ensures that the routes are scoped under the correct app, avoiding potential conflicts and making them easier to manage.
|
179
194
|
|
180
|
-
|
195
|
+
#### 3. Behavior When Resolving a Route:
|
196
|
+
|
197
|
+
When resolving the route using Django's `reverse()` function or any other method to resolve the URL, the latest version (highest version number) of the API will be returned. In this example, route for version 3 would be resolved:
|
198
|
+
|
199
|
+
```python
|
200
|
+
from django_api_versioning.decorators import endpoint
|
201
|
+
from django.http import JsonResponse
|
202
|
+
from django.views import View
|
203
|
+
from django.urls import reverse
|
204
|
+
|
205
|
+
|
206
|
+
@endpoint("users", version=3, app_name='account_app', view_name="users_list_api")
|
207
|
+
class UsersView(View):
|
208
|
+
|
209
|
+
def get(self, request):
|
210
|
+
|
211
|
+
return JsonResponse({"path of users_list_api view is": reverse('users_list_api')})
|
212
|
+
```
|
213
|
+
|
214
|
+
response body:
|
215
|
+
|
216
|
+
```json
|
217
|
+
{ "path of users_list_api view is": "api/v3/account_app/users" }
|
218
|
+
```
|
219
|
+
|
220
|
+
The generated URLs will be:
|
221
|
+
|
222
|
+
```bash
|
223
|
+
api/v1/account_app/users [name='users_list_api']
|
224
|
+
api/v2/account_app/users [name='users_list_api']
|
225
|
+
api/v3/account_app/users [name='users_list_api']
|
226
|
+
```
|
227
|
+
|
228
|
+
#### 4. Views with Version Less Than `API_MIN_VERSION` Are Automatically Ignored:
|
181
229
|
|
182
230
|
Any view whose `version` is less than the `API_MIN_VERSION` will be automatically ignored. This means clients will no longer have access to these older versions, **without the need to manually edit or remove code**. This is handled automatically by the package.
|
183
231
|
|
184
|
-
|
232
|
+
#### 5. URLs for Versions Between `API_MIN_VERSION` <= `version` <= `API_MAX_VERSION`:
|
185
233
|
|
186
234
|
Endpoints that have versions within the range defined by `API_MIN_VERSION` <= `version` <= `API_MAX_VERSION` will always have a corresponding URL generated. This ensures that only valid versions will be accessible, providing flexibility in version management.
|
187
235
|
|
188
|
-
|
236
|
+
## `endpoint` Decorator Function Definition
|
189
237
|
|
190
238
|
The `endpoint` decorator is designed to register API views with versioning support in a Django application. It provides flexibility in managing versioned endpoints and ensures backward compatibility with previous versions of the API.
|
191
239
|
|
{django-api-versioning-0.1.3 → django-api-versioning-0.1.4/django_api_versioning.egg-info}/PKG-INFO
RENAMED
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: django-api-versioning
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.4
|
4
4
|
Summary: Django API versioning decorator provides a solution for managing multiple API versions within the Django framework, enabling versioning through URLs with backward compatibility and automatically registering routes.
|
5
5
|
Home-page: https://github.com/mojtaba-arvin/django-api-versioning
|
6
6
|
Author: Mojtaba Arvin
|
@@ -107,6 +107,11 @@ def users_view(request):
|
|
107
107
|
|
108
108
|
In this example, the `users_view` function is decorated with the endpoint decorator. This specifies that the view is accessible under version `2` of the API and **supports backward compatibility**. The `backward=True` flag as default ensures that users can also access the previous version (version `1`) at `/api/v1/account_app/users`.
|
109
109
|
|
110
|
+
```bash
|
111
|
+
api/v1/account_app/users [name='users_list_api']
|
112
|
+
api/v2/account_app/users [name='users_list_api']
|
113
|
+
```
|
114
|
+
|
110
115
|
#### Example for Class-Based Views (CBVs):
|
111
116
|
|
112
117
|
For class-based views, you can apply the decorator to methods such as `get`, `post`, or any other HTTP method you need to handle. Here’s an example:
|
@@ -131,11 +136,13 @@ If you have already installed [Django Rest Framework](https://www.django-rest-fr
|
|
131
136
|
|
132
137
|
```python
|
133
138
|
from rest_framework.views import APIView
|
139
|
+
from rest_framework.permissions import AllowAny
|
134
140
|
from rest_framework.response import Response
|
135
141
|
from django_api_versioning.decorators import endpoint
|
136
142
|
|
137
143
|
@endpoint("users", version=2, app_name='account_app', view_name="users_list_api")
|
138
144
|
class UsersAPIView(APIView):
|
145
|
+
permission_classes = [AllowAny]
|
139
146
|
|
140
147
|
def get(self, request):
|
141
148
|
return Response({"message": "API Version 2 Users"})
|
@@ -143,10 +150,12 @@ class UsersAPIView(APIView):
|
|
143
150
|
|
144
151
|
#### URL Generation Based on Versioning:
|
145
152
|
|
146
|
-
Once the decorator is applied, the URLs for your API will be generated based on the version specified in the decorator. For example, if the `API_MIN_VERSION` in your settings.py is set to `1` and the version in the decorator is set to `2`, the following URLs will be available:
|
153
|
+
Once the decorator is applied, the URLs for your API will be generated based on the version specified in the decorator. For example, if the `API_MIN_VERSION` in your `settings.py` is set to `1` and the version in the decorator is set to `2`, the following URLs will be available:
|
147
154
|
|
148
|
-
|
149
|
-
|
155
|
+
```bash
|
156
|
+
api/v1/account_app/users [name='users_list_api']
|
157
|
+
api/v2/account_app/users [name='users_list_api']
|
158
|
+
```
|
150
159
|
|
151
160
|
The `API_MIN_VERSION` setting ensures that users can access the API using different versions, providing backward compatibility. You can adjust which versions are considered valid by modifying the `API_MIN_VERSION` and `version` numbers in the decorators.
|
152
161
|
|
@@ -160,8 +169,10 @@ The `API_MIN_VERSION` setting ensures that users can access the API using differ
|
|
160
169
|
|
161
170
|
The generated URLs will be:
|
162
171
|
|
163
|
-
|
164
|
-
|
172
|
+
```bash
|
173
|
+
api/v1/users [name='users_list_api']
|
174
|
+
api/v2/users [name='users_list_api']
|
175
|
+
```
|
165
176
|
|
166
177
|
**Without `version`:** If you don't pass `version` in the decorator, like this:
|
167
178
|
|
@@ -171,7 +182,9 @@ The generated URLs will be:
|
|
171
182
|
|
172
183
|
API versioning will be disabled (`API_BASE_PATH` as prefix will be removed) for that view. The only URL generated will be:
|
173
184
|
|
174
|
-
|
185
|
+
```bash
|
186
|
+
users [name='users_list_api']
|
187
|
+
```
|
175
188
|
|
176
189
|
**Setting `backward=False`:** By default, the `backward` parameter is set to `True`, which ensures backward compatibility. If you explicitly set `backward=False`, like this:
|
177
190
|
|
@@ -181,7 +194,9 @@ API versioning will be disabled (`API_BASE_PATH` as prefix will be removed) for
|
|
181
194
|
|
182
195
|
The generated URL will be only version 2:
|
183
196
|
|
184
|
-
|
197
|
+
```bash
|
198
|
+
api/v2/users [name='users_list_api']
|
199
|
+
```
|
185
200
|
|
186
201
|
4. Run the Server:
|
187
202
|
|
@@ -191,23 +206,56 @@ python manage.py runserver
|
|
191
206
|
|
192
207
|
## Notes
|
193
208
|
|
194
|
-
|
209
|
+
#### 1. `API_BASE_PATH` in settings Must Include `{version}`:
|
195
210
|
|
196
211
|
The `API_BASE_PATH` should always include `{version}` to ensure proper API versioning. This is important for correctly mapping API routes to different versions.
|
197
212
|
|
198
|
-
|
213
|
+
#### 2. Using `app_name` in the `endpoint` decorator:
|
199
214
|
|
200
215
|
It's recommended to fill in the `app_name` in the `endpoint` decorator to make the API URLs **more unique and organized**. This ensures that the routes are scoped under the correct app, avoiding potential conflicts and making them easier to manage.
|
201
216
|
|
202
|
-
|
217
|
+
#### 3. Behavior When Resolving a Route:
|
218
|
+
|
219
|
+
When resolving the route using Django's `reverse()` function or any other method to resolve the URL, the latest version (highest version number) of the API will be returned. In this example, route for version 3 would be resolved:
|
220
|
+
|
221
|
+
```python
|
222
|
+
from django_api_versioning.decorators import endpoint
|
223
|
+
from django.http import JsonResponse
|
224
|
+
from django.views import View
|
225
|
+
from django.urls import reverse
|
226
|
+
|
227
|
+
|
228
|
+
@endpoint("users", version=3, app_name='account_app', view_name="users_list_api")
|
229
|
+
class UsersView(View):
|
230
|
+
|
231
|
+
def get(self, request):
|
232
|
+
|
233
|
+
return JsonResponse({"path of users_list_api view is": reverse('users_list_api')})
|
234
|
+
```
|
235
|
+
|
236
|
+
response body:
|
237
|
+
|
238
|
+
```json
|
239
|
+
{ "path of users_list_api view is": "api/v3/account_app/users" }
|
240
|
+
```
|
241
|
+
|
242
|
+
The generated URLs will be:
|
243
|
+
|
244
|
+
```bash
|
245
|
+
api/v1/account_app/users [name='users_list_api']
|
246
|
+
api/v2/account_app/users [name='users_list_api']
|
247
|
+
api/v3/account_app/users [name='users_list_api']
|
248
|
+
```
|
249
|
+
|
250
|
+
#### 4. Views with Version Less Than `API_MIN_VERSION` Are Automatically Ignored:
|
203
251
|
|
204
252
|
Any view whose `version` is less than the `API_MIN_VERSION` will be automatically ignored. This means clients will no longer have access to these older versions, **without the need to manually edit or remove code**. This is handled automatically by the package.
|
205
253
|
|
206
|
-
|
254
|
+
#### 5. URLs for Versions Between `API_MIN_VERSION` <= `version` <= `API_MAX_VERSION`:
|
207
255
|
|
208
256
|
Endpoints that have versions within the range defined by `API_MIN_VERSION` <= `version` <= `API_MAX_VERSION` will always have a corresponding URL generated. This ensures that only valid versions will be accessible, providing flexibility in version management.
|
209
257
|
|
210
|
-
|
258
|
+
## `endpoint` Decorator Function Definition
|
211
259
|
|
212
260
|
The `endpoint` decorator is designed to register API views with versioning support in a Django application. It provides flexibility in managing versioned endpoints and ensures backward compatibility with previous versions of the API.
|
213
261
|
|
File without changes
|
File without changes
|
File without changes
|
{django-api-versioning-0.1.3 → django-api-versioning-0.1.4}/django_api_versioning/__init__.py
RENAMED
File without changes
|
{django-api-versioning-0.1.3 → django-api-versioning-0.1.4}/django_api_versioning/decorators.py
RENAMED
File without changes
|
{django-api-versioning-0.1.3 → django-api-versioning-0.1.4}/django_api_versioning/exceptions.py
RENAMED
File without changes
|
{django-api-versioning-0.1.3 → django-api-versioning-0.1.4}/django_api_versioning/registry.py
RENAMED
File without changes
|
{django-api-versioning-0.1.3 → django-api-versioning-0.1.4}/django_api_versioning/settings.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|