Building RESTful Python Web Services Chapter 1

Chapter 1:

Designing a RESTful API to interact with a simple SQLite database

There are many design considerations to decide on when starting a new project.  This section starts to go over some of those concerns, and the author concludes that Occam's Razor holds true, at least in the beginning of a new project.  Getting a proof of concept or a MVP (mininally viable project) is sometimes the best way to start moving forward with something.  There is a nice chart that goes over the HTTP verbs, and how they will be used in this project.  This is a good example of how to document things.  I think more programming books should also talk design, not just how tos.

Understanding the tasks performed by each HTTP method

The author quickly goes over the HTTP verbs, and how and what they will be used for in this project.  For those without an understanding of REST and its implementation, this is a nice overview of what they are and how they are used.

Working with lightweight virtual environments

I was excited to get to this part of the chapter one.  At work, we use Vagrant environments for developing locally, but they can be a pain to set up properly the first time.  Once they are set up, they almost always just work though.  Using the Python Virtual Environments is a very quick way to get up and developing different python projects, while also being able to keep them independent of each other.  The author does a good job of explaining every step of the process, and it was very easy to follow along and get set up very quickly.

I do suggest starting a text file inside your project with the commands you used to start up the virtual environment.  I was lazy the first time, and had to go over this section a few times, until I was smart enough to just write down the commands.

Setting up the virtual environment with Django REST framework

Once you have a virtual environment setup, you need to install all the proper packages to work with Django.  Again, this section was very easy to follow along with, and I was able to get setup in a matter of minutes.  He also goes over how to set up the configuration for your project. 

Creating the models

This is the first part of the book, where I start to have a little beef with the author.  There are several terms used in this section, and I don't think any of them are well defined.  The section is still incredibly useful, and mabye I'm just being picky.  I don't like "magic" in my programming.  I like to know what things mean, and why they do them.  He does do a good job of explaining how to construct a model, and the idiosyncrasies of Django.  For instance, when creating a model in Django, you do not need to add an id field for you database table, Django does this for you.

He also goes over the commands for how to use Django to create the database and the tables needed for the project in the book.

ORM - Object Relational mapping  An ORM is used to map data between incompatible systems, ie, Python, and a databsase. 

Managing serialization and deserialization

This section starts to contain the code needed to accomplish the project in question.  The example code is well written and easy to follow along with.  If you follow along exactly, it just works.  I would have enjoyed a more technical explanation of what we are trying to accomplish, and less of what we are doing.  While you can download the code examples, and I would, I recommend actually typing the code out, and trying to understand why you are doing what you are doing.  I feel like this is a better learning experience.  Your mileage may vary.

Writing API views

Again, this section contains a lot of code, and some decent explanation of how the code works in this instance, but little explanation of why the code works.  I also was not happy with the section on URLS.  I don't feel like I had learned anything, other than how to cut and paste code.

Here is a link to the documentation.  I would read it after you finish this chapter, and make sure you have a good understanding of how and why they work.
https://docs.djangoproject.com/en/2.0/topics/http/urls/

Making HTTP requests to the API

The final section of this chapter goes over various ways to send requests to your new API.  Discussed are command-line tools, and GUI tools.  Introduced in this section, is curl and httpie.  I really like httpie, and will be using it in the future for new projects.  Once you have finished this section, I think you will have a thorough understanding of how curl and httpie works.  I appreciate the author giving detail instructions, and giving the equivalent examples of both command line tools.

He also goes over Postman, and PyCharm.  I have used Postman in the past, and I like it.  I tried to use his PyCharm instructions, but I never could get it to work.  You can use the GUI tools, but know they are more subject to change and break than the command line tools.  I don't think curl has changed much since it was developed in 1997.  It should always just work.

Comments

Popular posts from this blog

Go Programming Blueprints, Chapter 2, Adding User Accounts

Successful Big Game Hunting Chapter 10