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

FastAPI · Decorator

get

get 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.

How it works

get is a method on FastAPI and APIRouter used as a decorator. It registers the decorated function as the handler for the supplied URL path and configures how FastAPI describes, validates, and serves that GET operation, including its response model, status code, dependencies, OpenAPI metadata, and response class.

Syntax

get(
    path,
    *,
    response_model=Default(None),
    status_code=None,
    tags=None,
    dependencies=None,
    summary=None,
    description=None,
    response_description="Successful Response",
    responses=None,
    deprecated=None,
    operation_id=None,
    response_model_include=None,
    response_model_exclude=None,
    response_model_by_alias=True,
    response_model_exclude_unset=False,
    response_model_exclude_defaults=False,
    response_model_exclude_none=False,
    include_in_schema=True,
    response_class=Default(JSONResponse),
    name=None,
    callbacks=None,
    openapi_extra=None,
    generate_unique_id_function=Default(generate_unique_id)
)

Parameters

NameTypeDescription
pathstrURL path for the path operation.
response_modelAnyPydantic-compatible type used for the response.
status_codeint | NoneHTTP status code for the response.
tagslist[str] | NoneOpenAPI tags for the operation.
dependenciesSequence[Depends] | NoneDependencies applied to the operation.
summarystr | NoneShort OpenAPI summary.
descriptionstr | NoneOpenAPI description.
response_descriptionstrDescription of the successful response.
responsesdict[int | str, dict[str, Any]] | NoneAdditional response definitions.
deprecatedbool | NoneMarks the operation as deprecated.
operation_idstr | NoneExplicit OpenAPI operation identifier.
response_model_includeIncEx | NoneFields to include in the response model.

Returns

A decorator that registers the supplied function as a GET path operation.

Key points

  • Use get to register a FastAPI path operation for HTTP GET requests.
  • The required path argument specifies the URL path, for example /items.
  • response_model declares the type FastAPI uses for response validation, serialization, and schema generation.

Example: A basic GET path operation

from fastapi import FastAPI

app = FastAPI()

@app.get("/items/")
def read_items():
    return [{"name": "Empanada"}, {"name": "Arepa"}]

Registers a synchronous function as the handler for GET requests to /items/.

When to use it

Expose read-only endpoints

Read a collection or resource over HTTP GET.

Validate and document responses

Describe returned data and generate its API schema.

Attach operation dependencies

Apply authentication, authorization, or other shared logic.

Add OpenAPI metadata

Customize generated API documentation.

Interview questions

QWhat does app.get() do?

get registers a path operation using the HTTP GET method. It accepts the URL path first, then keyword-only options that configure response handling and OpenAPI metadata.

Follow-up: How would you document a non-default successful response? Pass response_model, and use status_code or responses when the operation needs explicit response documentation.

QWhat is the purpose of the path argument?

The required path is the URL path for the operation, such as /items. The decorated function becomes the path operation function that handles requests matching that path and method.

Follow-up: What is the difference between a path and an operation? The path identifies the URL portion, while get identifies the HTTP operation applied to it.

QWhich kinds of configuration does get support?

The decorator can configure response_model, status_code, dependencies, tags, summaries, descriptions, response inclusion, and the response class. These options are supplied to the decorator rather than to the handler's parameters.

Follow-up: How can an operation be hidden from generated OpenAPI documentation? Set include_in_schema=False in the decorator.

  • FastAPI
  • APIRouter
  • get
  • post
  • Path Operation Configuration
  • response_model
  • Depends

Source: FastAPI class - FastAPI. Checked 2026-10-15.