AskReference
ConceptIntermediate

What are the four main locations in an HTTP request where FastAPI can find data?

FastAPI can find data in four main locations within an HTTP request: the headers, the URL path, query parameters (after the ?), and the HTTP body.

According to the chapter, data may come from different parts of an HTTP message. FastAPI uses dependency injection to let you specify where data is located. The four main locations are: header, meaning in the HTTP headers; path, meaning in the URL; query, meaning after the ? in the URL; and body, meaning in the HTTP body. Other sources like environment variables and configuration settings exist but are more indirect and not considered among these four main request locations.

Key points

  • Header: data carried in the HTTP headers.
  • Path: data embedded in the URL path.
  • Query: data after the ? in the URL.
  • Body: data in the HTTP request body.
  • FastAPI lets you declare which part of the request each input comes from.
Source:FastAPI: Modern Python Web Development· Web Layer· p. 111–119

Related questions

Cover of FastAPI: Modern Python Web Development

FastAPI: Modern Python Web Development

Bill Lubanovic;

First Edition · O'Reilly Media, Inc.

View this ebook