Review: Django for APIs by William S. Vincent

Camilo Matajira Avatar

1. Author’s purpose

The purpose of the author is to provide a resource for developers to learn the Django REST Framework –henceforth DRF– (p.3).
For the author, there are no good resources to learn DRF (p.3) hence the need for this book.

2. Main themes of the book

This book resembles a written-down version of a tutorial. In this sense, it introduces some concepts and then takes the reader by the hand and shows him how to build different projects applying those concepts.
If a new feature is introduced, the author shows where the changes need to be made to the existing code. In this regard, this is a very practical book.

The book is divided into the following chapters:
Chapter 1. Initial set up
This chapter guides the readers on CLI basics; installing python; virtual environments; django installation; and git on both MacOS and Windows.
This chapter covers the bare minimum to run Django on your local machine.

Chapter 2. Web APIs
This chapter covers a little history of the internet and a bit of web terminology including HTTP verbs, REST, and status codes.
This is useful because if you are starting to build APIs, how would you know the existence of HTTP verbs (GET, POST, PUT, PATCH, INFO, etc.)?
The same for the status codes.

Chapter 3. Library Website
In this chapter, the author builds a small app to show books in traditional Django.
He shows how to create the unit tests and the HTML templates.

Chapter 4. Library API
In this chapter, the author creates the same app as Chapter 3, but as Rest API using DRF.
He shows how to install DRF, how to unit test, and how to make the deployment to Heroku.

Chapter 5. Todo API
In this chapter, the highlights are the introduction of CORS and CSRF in DRF.
Also, it is useful the custom user model.

Chapter 6. Blog API
In this chapter the author builds a Blog API with the concepts of the previous chapters specially users, permissions and CRUD.

Chapter 7. Permissions
This chapter covers project-level permissions, view-level permissions, and custom permissions.
Basically, how to set who can do what.

Chapter 8. User authentication
This chapter covers basic authentication, session authentication, and token authentication.
At a practical level, it also covers how to log in and authenticate using dj-rest-auth and django-allauth and how to create custom permissions.

Chapter 9. Viewsets and Routers
This chapter introduces Viewsets and Routers as abstractions that help developers write less code (p171)

Chapter 10. Schemas and documentation
This chapter shows how to generate OpenAPI schemas with django-spectacular and how to create dynamic schemas with Redoc or SwaggerUI format.

Chapter 11. Production deployment
This chapter gives some to-do list on deploying to production, in a service like Heroku.

3. Uniqueness of the book

What makes this book unique is that it focuses on DRF. Focusing on DRF is important because Django is mostly used today as an API and not as a full-stack framework. The reason for this is probably the advantages of decoupling the backend and the frontend. If they are decoupled, the frontend could be written in a Javascript framework like React or Angular or could be written in Java for Android or Swift for IOS apps (p.1).
With this in mind, this book provides a valuable skill that is in demand by the market.

4. Was the author successful in his objective?

Yes for me the author fulfilled his objective. The author provided a resource that includes the main topics of DRF including examples and some good practices.
At the end of the book, the reader would be able to create a basic API taking advantage of the resources provided by DRF.

5. Comparison against the best book in the field

In my perspective, the best book in the field is Two Scoops of Django 3.X by Daniel and Audrey Roy Greenfield.
This book is the Django Bible and covers several Django topics with good depth. However, out of its 37 chapters, it only dedicates one to the creation of APIs with DRF, and the topic is not covered in depth.
This means that Django for APIs provides unique content that is not present in the Two Scoops of Django book.

Another difference is the target audience. Two Scoops of Django is aimed at experienced/advanced professionals. It provides key and specific good practices for experienced users. However, this means that it’s not very friendly to new and intermediate users. Sometimes the concepts are difficult to grasp for intermediate users (or at least for myself). Instead, Django for APIs is friendly to intermediate users.

Nonetheless, both books are similar in that they are not aimed at new Django Developers. Despite the efforts done in this book in teaching how to set up python, virtual environments, and using the CLI, the book would not be reachable to a new Django Developer because the basics of Django were not included, for example, the ORM.

In this sense, these two books are complimentary.

7. Conclusion

I recommend this book to intermediate Django Developers. This book offers a unique resource: the introduction to the DRF library.
However, for new and advanced Django developers this book will not be very useful. For the new developers the book assumes that you know the Django basics, and for the advanced it does not provide profound advice at the level of a book like Two Scoops of Django 3.X.

However, intermediate and advanced Django developers can profit from the contents of the book. I recommend especially Chapter 8 “User Authentication” which covers the topic with great depth.

Camilo Matajira Avatar