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

Error handling

Clients will make mistakes or send invalid data when sending requests, and our RESTful API needs to catch them and inform the client about what went wrong to enable the client to anticipate accordingly. The client-server communication for a DRF-based RESTful API in case of an error generally covers these steps:

  1. The client sends a request to an endpoint.
  2. The RESTful API at the endpoint parses the request.
  3. The URL mechanism and the serializer in the RESTful API validate the request and catch an error.
  4. The RESTful API sends an error message and a corresponding HTTP status code back to the client.
  5. The client parses the request.
  6. The client signals the error and catches it with alternate processing.

To implement the RESTful API part in this process, we need to handle possible errors, which falls apart in the following areas:

  • Handling wrong formatted requests, such as a missing data object, when creating new data through a POST request...