6 Building REST APIs with Python

 

This chapter covers

  • Adding URL query parameters to an endpoint using FastAPI
  • Disallowing the presence of unknown properties in a payload using pydantic and marshmallow
  • Implementing a REST API using flask-smorest
  • Defining validation schemas and URL query parameters using marshmallow

In previous chapters, you learned to design and document REST APIs. In this chapter, you’ll learn to implement REST APIs by working on two examples from the CoffeeMesh platform, the on-demand coffee delivery application that we introduced in chapter 1. We’ll build the APIs for the orders service and for the kitchen service. The orders service is the main gateway to CoffeeMesh for customers of the platform. Through it they can place orders, pay for those orders, update them, and keep track of them. The kitchen service takes care of scheduling orders for production in the CoffeeMesh factories and keeps track of their progress. We’ll learn best practices for implementing REST APIs as we work through these examples.

6.1 Overview of the orders API

6.2 URL query parameters for the orders API

6.3 Validating payloads with unknown fields

6.4 Overriding FastAPI’s dynamically generated specification

6.5 Overview of the kitchen API

6.6 Introducing flask-smorest

6.7 Initializing the web application for the API

6.8 Implementing the API endpoints

6.9 Implementing payload validation models with marshmallow

6.10 Validating URL query parameters

6.11 Validating data before serializing the response

6.12 Implementing an in-memory list of schedules

6.13 Overriding flask-smorest’s dynamically generated API specification

Summary