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.