Book Image

Python API Development Fundamentals

By : Jack Chan, Ray Chung, Jack Huang
Book Image

Python API Development Fundamentals

By: Jack Chan, Ray Chung, Jack Huang

Overview of this book

Python is a flexible language that can be used for much more than just script development. By knowing the Python RESTful APIs work, you can build a powerful backend for web applications and mobile applications using Python. You'll take your first steps by building a simple API and learning how the frontend web interface can communicate with the backend. You'll also learn how to serialize and deserialize objects using the marshmallow library. Then, you'll learn how to authenticate and authorize users using Flask-JWT. You'll also learn how to enhance your APIs by adding useful features, such as email, image upload, searching, and pagination. You'll wrap up the whole book by deploying your APIs to the cloud. By the end of this book, you'll have the confidence and skill to leverage the power of RESTful APIs and Python to build efficient web applications.
Table of Contents (12 chapters)

The PATCH Method

We have been using the PUT HTTP method all along for data updates. However, the actual usage of the PUT method is to Replace (Create or Update). For example, PUT /items/1 means to replace everything in /items/1. If this item already exists, it will be replaced. Otherwise, it will create a new item. PUT must contain all attribute data for items/1.

This doesn't seem to work very well in all cases. If you just want to update only one of the attributes of items/1, you need to retransmit all the attributes of items/1 to the server, which is not efficient at all. So, there is a new HTTP method: PATCH. The PATCH method was invented to do a partial update. With this method, we need to pass in only the attributes that need to be modified to the server.

Exercise 37: Using the PATCH Method to Update the Recipe

In this exercise, we will change the recipe update method from PUT to PATCH. We will also use the serialization/deserialization approach to transmit the recipes...