django-rest-framework-condition
This package allows you to use @condition decorator from Django on ViewSet or
APIView from Django Rest Framework. In other words, you can use http headers
ETag and Last-modified with you APIs.
It doesn't create custom implementation of etags or last-modified header but uses ones from Django which means you can be sure it will be updated by Django's authors.
Similarly as in Django you can use shortcut decorators @last_modified and
@etag.
Tested with:
- Python: 2.7, 3.7
- Django: 1.11, 2.0, 2.1, 2.2
- Django Rest Framework: 3.8, 3.9
Installation
pip install django-rest-framework-condition
Usage
Use decorators same way as with Django views.
Last-modified example
from datetime import datetime
from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework_condition import last_modified
class LastModifiedApiView(APIView):
@last_modified(lambda _: datetime(2019, 1, 1))
def get(self, request):
return Response({'data': 'I have Last-Modified header!'})
ETag example
import hashlib
from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework_condition import etag
def my_etag(request, *args, **kwargs):
return hashlib.md5(':'.join(request.GET.dict().values()).encode('utf-8')).hexdigest()
class EtagApiView(APIView):
@etag(my_etag)
def get(self, request):
return Response({'data': 'I have Etag!'})
Both ETag and Last-Modified example
import hashlib
from datetime import datetime
from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework_condition import condition
def my_etag(request, *args, **kwargs):
return hashlib.md5(':'.join(request.GET.dict().values()).encode('utf-8')).hexdigest()
def my_last_modified(request, *args, **kwargs):
return datetime(2019, 1, 1)
class ConditionApiView(APIView):
@condition(etag_func=my_etag, last_modified_func=my_last_modified)
def get(self, request):
return Response({'data': 'I have both Last-Modified and Etag!'})
Metadata
Release files for django-rest-framework-condition 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django-rest-framework-condition-0.1.1.tar.gz | 4.5 kB | Without provenance | Details for django-rest-framework-condition-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_rest_framework_condition-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for django_rest_framework_condition-0.1.1-py3-none-any.whl |
Total release size: 13.6 kB
Release files / django-rest-framework-condition-0.1.1.tar.gz
| Download URL | django-rest-framework-condition-0.1.1.tar.gz |
|---|---|
| Size | 4.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e8fb77602013270fd86597aa213142ac2d9f086ab366da56e113f38d632ee0f9
|
|
BLAKE2b-256 checksum How to use checksums |
c5954f5602e0ebf129a97bb97e21cda46c4f31acba288a19ff601ce4684638e2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2
|
Release files / django_rest_framework_condition-0.1.1-py3-none-any.whl
| Download URL | django_rest_framework_condition-0.1.1-py3-none-any.whl |
|---|---|
| Size | 9.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
04c90e454a0370d974d5d79eb7aa7e906da32eababe3a65b2f4f77ae47629b7a
|
|
BLAKE2b-256 checksum How to use checksums |
b6cff261dbb2f694170118852e673c6a5c2e3b43fefe2e46918760de45e00554
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2
|
Security for django-rest-framework-condition 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.