Book Image

Hands-On Microservices with Django

By : Tieme Woldman
Book Image

Hands-On Microservices with Django

By: Tieme Woldman

Overview of this book

Are you a Django developer looking to leverage microservices to create optimized and scalable web applications? If yes, then this book is for you. With microservices, you can split an application into self-contained services, each with a specific scope running asynchronously while collectively executing processes. Written by an experienced Python developer, Hands-On Microservices with Django teaches you how to develop and deploy microservices using Django and accompanying components such as Celery and Redis. You'll start by learning the principles of microservices and message/task queues and how to design them effectively. Next, you’ll focus on building your first microservices with Django RESTful APIs (DFR) and RabbitMQ, mastering the fundamentals along the way. As you progress, you’ll get to grips with dockerizing your microservices. Later, you’ll discover how to optimize and secure them for production environments. By the end of this book, you’ll have the skills you need to design and develop production-ready Django microservices applications with DFR, Celery/RabbitMQ, Redis, and Django's cache framework.
Table of Contents (18 chapters)
Free Chapter
1
Part 1:Introducing Microservices and Getting Started
5
Part 2:Building the Microservices Foundation
11
Part 3:Taking Microservices to the Production Level

Building RESTful APIs with DRF

DRF is an extension of Django for developing and deploying RESTful APIs. In Chapter 3, Setting Up the Development and Runtime Environment, we installed DRF through pip as a Python package, and in this section, we’ll apply DRF to develop a RESTful API for our sample application. DRF provides us with these functionalities:

  • The actual API that clients can access through one or more endpoints
  • Serializers that collaborate with Django ORM to transform data from data source to JSON and the other way around
  • A set of pre-defined views to quickly and easily create API endpoints for CRUD operations

If we transpose this to Django and zoom in on the Django file structure, we’ll see that DRF is primarily about these standard Django files:

  • models.py: Containing the data model for our API
  • views.py: Containing the API viewset and specifications for CRUD operations
  • urls.py: Containing the endpoints for our API views
  • ...