aboutsummaryrefslogtreecommitdiffstats
path: root/docs/api-guide/throttling.md
diff options
context:
space:
mode:
authorTom Christie2012-09-13 09:39:16 +0100
committerTom Christie2012-09-13 09:39:16 +0100
commitb16c45aa6dfb5937d01f0c89273cd24f5e729f60 (patch)
tree5182360400b8d0fa1740020d8164d40b9bbfaf8a /docs/api-guide/throttling.md
parent003a65f0e094e59b5462fcd0607bf290d80cc5aa (diff)
downloaddjango-rest-framework-b16c45aa6dfb5937d01f0c89273cd24f5e729f60.tar.bz2
Tweak throttling/permissions/auth docs
Diffstat (limited to 'docs/api-guide/throttling.md')
-rw-r--r--docs/api-guide/throttling.md67
1 files changed, 64 insertions, 3 deletions
diff --git a/docs/api-guide/throttling.md b/docs/api-guide/throttling.md
index ae8f7b98..b958d2b5 100644
--- a/docs/api-guide/throttling.md
+++ b/docs/api-guide/throttling.md
@@ -8,8 +8,69 @@
[cite]: https://dev.twitter.com/docs/error-codes-responses
-## PerUserThrottle
+Throttling is similar to [permissions], in that it determines if a request should be authorized. Throttles indicate a temporary state, and are used to control the rate of requests that clients can make to an API.
-## PerViewThrottle
+As with permissions, multiple throttles may be used. Your API might have a restrictive throttle for unauthenticated requests, and a less restrictive throttle for authenticated requests.
-## Custom throttles \ No newline at end of file
+Another scenario where you might want to use multiple throttles would be if you need to impose different constraints on different parts of the API, due ato some services being particularly resource-intensive.
+
+Throttles do not necessarily only refer to rate-limiting requests. For example a storage service might also need to throttle against bandwidth.
+
+## How throttling is determined
+
+As with permissions and authentication, throttling in REST framework is always defined as a list of classes.
+
+Before running the main body of the view each throttle in the list is checked.
+If any throttle check fails an `exceptions.Throttled` exception will be raised, and the main body of the view will not run.
+
+## Setting the throttling policy
+
+The default throttling policy may be set globally, using the `DEFAULT_THROTTLES` setting. For example.
+
+ API_SETTINGS = {
+ 'DEFAULT_THROTTLES': (
+ 'djangorestframework.throttles.AnonThrottle',
+ 'djangorestframework.throttles.UserThrottle',
+ )
+ 'DEFAULT_THROTTLE_RATES': {
+ 'anon': '100/day',
+ 'user': '1000/day'
+ }
+ }
+
+You can also set the throttling policy on a per-view basis, using the `APIView` class based views.
+
+ class ExampleView(APIView):
+ throttle_classes = (UserThrottle,)
+
+ def get(self, request, format=None):
+ content = {
+ 'status': 'request was permitted'
+ }
+ return Response(content)
+
+Or, if you're using the `@api_view` decorator with function based views.
+
+ @api_view('GET')
+ @throttle_classes(UserThrottle)
+ def example_view(request, format=None):
+ content = {
+ 'status': 'request was permitted'
+ }
+ return Response(content)
+
+## AnonThrottle
+
+The `AnonThrottle` will only ever throttle unauthenticated users. The IP address of the incoming request is used to identify
+
+`AnonThrottle` is suitable if you want to restrict the rate of requests from unknown sources.
+
+## UserThrottle
+
+`UserThrottle` is suitable if you want a simple restriction
+
+## ScopedThrottle
+
+## Custom throttles
+
+[permissions]: permissions.md \ No newline at end of file