diff --git a/api-guide/throttling.html b/api-guide/throttling.html index 5e9ad789a..7262dff1e 100644 --- a/api-guide/throttling.html +++ b/api-guide/throttling.html @@ -168,6 +168,26 @@ def example_view(request, format=None):
rate
property on the class, which may be provided by overriding UserThrottle
and setting the property.DEFAULT_THROTTLE_RATES['user']
setting.An API may have multiple UserRateThrottles
in place at the same time. To do so, override UserRateThrottle
and set a unique "scope" for each class.
For example, multiple user throttle rates could be implemented by using the following classes...
+class BurstRateThrottle(UserRateThrottle):
+ scope = 'burst'
+
+class SustainedRateThrottle(UserRateThrottle):
+ scope = 'sustained'
+
+...and the following settings.
+API_SETTINGS = {
+ 'DEFAULT_THROTTLES': (
+ 'example.throttles.BurstRateThrottle',
+ 'example.throttles.SustainedRateThrottle',
+ )
+ 'DEFAULT_THROTTLE_RATES': {
+ 'burst': '60/min',
+ 'sustained': '1000/day'
+ }
+}
+
UserThrottle
is suitable if you want a simple global rate restriction per-user.
The ScopedThrottle
class can be used to restrict access to specific parts of the API. This throttle will only be applied if the view that is being accessed includes a .throttle_scope
property. The unique throttle key will then be formed by concatenating the "scope" of the request with the unqiue user id or IP address.