6 Implementing 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
  • Automatically generating Pydantic models from an OpenAPI specification
  • Implementing a REST API using Flask-smorest
  • Defining validation schemas and URL query parameters using marshmallow

In this chapter, we implement two REST APIs from the CoffeeMesh platform, the on-demand coffee delivery application that we introduced in chapter 1. We’ll implement 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 them, 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 the implementation of 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      Automatically loading validation schemas from the specification

 
 

6.5      Overview of the kitchen API

 
 
 

6.6      FastAPI vs flask-smorest

 

6.7      Initializing the web application for the API

 
 

6.8       Implementing the API endpoints

 

6.9      Implementing payload validation models

 
 

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  Summary

 
 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest