2 A basic API implementation

 

This chapter covers

  • Reading and understanding the requirements of an API specification
  • Structuring our application into a data layer, an application layer, and an interface layer
  • Implementing API endpoints using FastAPI
  • Implementing data validation models (schemas) using Pydantic
  • Running an application with Docker

In this chapter, we implement the API for the orders service, which is one of the microservices of the CoffeeMesh website, the project that we introduced in chapter 1. In doing so, you will get an early peek into the concepts and processes that we dissect in more detail throughout this book. In this chapter, I go quickly through the steps and concepts involved in the implementation of a microservice, and build an intuition of the main ideas that we will cover in more detail in later chapters.

The code for this chapter is available under the folder ch02 of the GitHub repository provided with this book.

2.1   Introducing the API specification

This section discusses the requirements for implementing the API of the orders microservice. The orders microservice allows us to manage orders made through the CoffeeMesh website. It’s a central service of the CoffeeMesh website and it integrates with other services of the CoffeeMesh platform, as shown in figure 2.1. You’ll find an explanation of how we broke down the CoffeeMesh platform into the set of microservices shown in figure 2.1 in chapter 3.

2.2   High-level architecture of the orders application

2.3   Implementing the API endpoints

2.4   Validating API requests payloads and marshalling responses

2.5   Connecting the API layer with the Application layer

2.6   Dockerizing the application

2.7   Summary

sitemap