Author: Muhammad AbdulMoiz
Muhammad AbdulMoiz
Software Engineer @
LinkedIn profile
Github profile
Understanding Throttling
Django Throttling policy
Throttle types
Dig down in implementation
https://www.django-rest-framework.org/api-guide/throttling/
REST_FRAMEWORK = { 'DEFAULT_THROTTLE_CLASSES': [ 'rest_framework.throttling.AnonRateThrottle', 'rest_framework.throttling.UserRateThrottle' ], 'DEFAULT_THROTTLE_RATES': { 'anon': '100/day', 'user': '1000/day' } }
from rest_framework.response import Response from rest_framework.throttling import UserRateThrottle from rest_framework.views import APIView class ExampleView(APIView): throttle_classes = [UserRateThrottle] def get(self, request, format=None): content = { 'status': 'request was permitted' } return Response(content)
@api_view(['GET']) @throttle_classes([UserRateThrottle]) def example_view(request, format=None): content = { 'status': 'request was permitted' } return Response(content)
Annon Rate Throttle
User Rate Throttle
Scoped Throttle
Custom Throttle
Text
By Muhammad AbdulMoiz
Understanding and implementing Django Throttline
Software Developer at Sastaticket.pk