Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

API reference

FastAPI API reference

FastAPI async API framework

Identifiers
16
With full guides
14
Types
4

Topics covered

  • Path operations
  • Pydantic models
  • Dependencies
  • Query & path params
  • Request body
  • Auth
  • Background tasks
  • Async

Class

NameWhat it does
FastAPIFastAPI is the application class for building an API. Instantiate it, then register HTTP path operations on the resulting application object.
APIRouterAPIRouter groups related FastAPI path operations into a reusable router. Shared prefixes, tags, dependencies, responses, lifecycle handlers, and schema settings can be configured once and applied when the router is included in an application.
HTTPExceptionFastAPI's HTTPException is raised to send a deliberate client-facing HTTP error. It accepts a status code plus optional JSON-compatible detail data and response headers.
BaseModelBaseModel is the Pydantic superclass for defining typed data models in FastAPI. Subclass it to describe request bodies with standard Python annotations, enabling structured input handling and automatic API schema generation.
RequestRequest is FastAPI's raw HTTP request object, injected into path operations or dependencies through a type annotation. Use it to inspect request-level data directly when standard parameter declarations do not provide the needed access.
ResponseFastAPI's Response class represents an HTTP response that can be injected to modify headers or cookies, or constructed and returned directly. Its constructor controls content, status, headers, media type, and background work.
BackgroundTasksBackgroundTasks collects callable work and runs it after FastAPI sends the response. FastAPI injects it into path operations or dependencies, and add_task() accepts a synchronous or asynchronous function with its arguments.

Function

NameWhat it does
DependsDepends declares a callable that FastAPI resolves and injects into a route or another dependency. It also controls per-request result caching and, for yield dependencies, cleanup timing.
PathPath declares a URL path parameter for a FastAPI path operation. It provides schema metadata and validation while the parameter remains required because it is part of the route.
QueryQuery declares a FastAPI query parameter and adds validation, documentation metadata, and OpenAPI schema information. Use it with Annotated to express constraints such as length limits or numeric bounds.
BodyFunction
HeaderHeader declares an HTTP request-header parameter for a FastAPI path operation or dependency. It supports defaults, validation, metadata, aliases, and automatic underscore-to-hyphen conversion.
FormForm declares FastAPI endpoint parameters that are read from submitted form data instead of JSON or query parameters. It supports the same style of configuration as other parameter helpers, including validation and aliases.

Decorator

NameWhat it does
getget is a FastAPI decorator method that registers a function as the handler for an HTTP GET path. Its keyword arguments configure response behavior and generated OpenAPI metadata.
postDecorator

Module

NameWhat it does
statusFastAPI's status module provides named integer constants for HTTP and WebSocket status codes. Import it from fastapi to use readable values such as status.HTTP_200_OK in application code.

Search across every package and filter by type in your dashboard.

Start learning