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)

1: Your First Step

Activity 1: Sending Requests to Our APIs Using Postman

Solution

  1. First, we will get all of the recipes. Select GET as our HTTP method in the drop-down list.
  2. Enter the request URL http://localhost:5000/recipes.
  3. Click the Send button. The result can be seen in the following screenshot:
    Figure 1.14: Getting all the recipes

    In the HTTP response, you will see the HTTP status 200 OK in the top-right corner of the response panel. That means the request has been successful. The time next to it shows 7ms, which is the time spent on the request. And the size of the response, including the header and body, is 322 bytes. The details of the recipes, in JSON format, are shown in the Body panel.

  4. Next, we are going to use the POST method to create a recipe. We will send an HTTP POST request to http://localhost:5000/recipes.
  5. Create a new tab next to the Get Request Tab by clicking on the + button. Select POST as the HTTP method. Type in http://localhost:5000...