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 expands on the @api_view decorator.  It allows us to get several neat features:
  1. The ability to accept JSON or XML data.
  2. The ability to specify which verbs we will accept with our api. 

Browsing the API

The author shows us how we get an easy web page to browse through our API, with no coding involved.  This is a very nice feature of Django.  For further study follow this link Django Rest Framework Documentation

Designing a RESTful API to interact with a complext PostgresSQL database

 We begin to design more complex tables to make our API more robust.  The author has chosen PostGres which is a very nice database system.  There is some prerequisite database knowledge to really know what he is talking about.

Understanding the tasks performed by each HTTP method

We are told about the PUT and PATCH methods.
PUT allows us to replace a whole resource, while PATCH will allow us to update a resource.
A resource being a Python Object that corresponds to rows in the database.

Declaring relationships with the models

The author does a good job of showing how to use Django classes to build relational database structures and how to use Postgre.

Managing Serialization and deserialization with relationships and hyperlinks

This section is essentially the same text over and over again.  It does explain the new serializer section, but once you've read part of the new code, you've read it all.  It could be really helpful for a new developer, but for a seasoned developer, I would skip most of the section.

Creating class-base views and using generic classes

I found this part very interesting.  Lightbulbs started going off over my head.  It introduces two new functions from rest framework class that allows us to replace the code we wrote earlier with HTTP verbs to do all of our updates.  This is a great way to reduce boilerplate code, and start really getting things done.

Taking advantage of generic class based views

This is another quick section on code and what the code should do.  As always, my major complaint is, there is a lot of magic here.  I would have preferred less code examples, and more explanation of what is going on.  I prefer more details on why it works, and less on how to do it.

Working with endpoints for the API

This is a tutorial on how easy it is to interact with our API.  With just a few classes we have functioning API.

Creating and retrieving related resources

This chapter concludes with several examples of how easy it is to update the database with the few magic lines of code we added earlier.


Comments

Popular posts from this blog

Go Programming Blueprints, Chapter 2, Adding User Accounts

Successful Big Game Hunting Chapter 10