Posts

Showing posts from May, 2018

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 ...

Building RESTful Python Web Services Chapter 3

Chapter 3: Improving and Adding Authentication to an API With Django Adding unique constraints to the models The author introduces the unique=True keyword/phrase.  This allows Django to add the unique constraint to the database table.  He also goes over how to run migrations one more time.  We then test the code, and voila it just works.  I was personally glad for the rerun of the makemigrations and migrate commands.  I've been using it for a while now, so it wasn't real helpful, but I can remember in the beginning, having to wrack my brain for the correct commands to run to alter the database.  Updating a single field for a resource with the PATCH method This is a very quick section on, you guessed it, the PATCH method.  Very simple, and straightforward to use.  I am still a little confused on how all this works.  I think the author would have done a better job explaining the secret sauce in the rest_framework.  Some self stud...

Building RESTful Python Web Services Chapter 2

Chapter 2: Working with Class-based Views and Hyperlinked API's in Django Use Model Serializers to Eliminate Duplicate Code This is a short section that implements a better serializer class from Chapter 1.  My complain is much the same as always, there is too much "magic" here.  I would have preferred a more robust explanation of why the author is doing what he is doing, rather than what he is trying to accomplish. Working With Wrappers to Write API Views We are introduced to the new HTTP verb OPTIONS , which when sent to our API will reply with how to use the API.  This can be very useful information for us in the future, especially when dealing with new API's with minimal documentation. We are also introduced to the @api_view decorator.  Decorators in Django are very useful.  They will allow us to do many things including allowing cross site scripting requests. Using the default parsing and rendering options and move beyond JSON This section expand...