Chapter 3: Response Models and Error Handling

Response models serve as templates for returning data from an API route path. They are built on Pydantic to properly render a response from requests sent to the server.

Error handling includes the practices and activities involved in handling errors from an application. These practices include returning adequate error status codes and error messages.

By the end of this chapter, you will know what a response is and what it consists of, and you’ll know about error handling and how to handle errors in your FastAPI application. You will also know how to build response models for request responses using Pydantic.

In this chapter, we’ll be covering the following topics:

  • Responses in FastAPI
  • Building a ...

Get Building Python Web APIs with FastAPI now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.