Building RESTful Python Web Services Chapter 4
Chapter 4: Throttling, filtering, testing, and deploying an API with Django Understanding Throttling Classes We are introduced to the SimpleRateThrottle (Django Link) class. There are three options we can use AnonRateThrottle UserRateThrottle ScopedRateThrottle Configuring throttling policies The easiest way to configure throttling is to add it to the REST_FRAMEWORK dictionary in our settings.py file. You can set rates for any time period of a day or less. To use more targeted rates of throttling, you still add them to the settings file, but then you need to add a few more lines of code to the classes that need them. Testing throttling policies We can easily test our new polices by running code in a loop to send requests to the API. Once you receive too many requests, you will get a HTTP Code 429, and the API will send back the number of seconds, until it believes you can try again. Understanding filtering, searching, and ordering classes The author ...