Expose read-only endpoints
Read a collection or resource over HTTP GET.
FastAPI · Decorator
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.
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.
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)
)| Name | Type | Description |
|---|---|---|
path | str | URL path for the path operation. |
response_model | Any | Pydantic-compatible type used for the response. |
status_code | int | None | HTTP status code for the response. |
tags | list[str] | None | OpenAPI tags for the operation. |
dependencies | Sequence[Depends] | None | Dependencies applied to the operation. |
summary | str | None | Short OpenAPI summary. |
description | str | None | OpenAPI description. |
response_description | str | Description of the successful response. |
responses | dict[int | str, dict[str, Any]] | None | Additional response definitions. |
deprecated | bool | None | Marks the operation as deprecated. |
operation_id | str | None | Explicit OpenAPI operation identifier. |
response_model_include | IncEx | None | Fields to include in the response model. |
A decorator that registers the supplied function as a GET path operation.
get to register a FastAPI path operation for HTTP GET requests.path argument specifies the URL path, for example /items.response_model declares the type FastAPI uses for response validation, serialization, and schema generation.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/.
Read a collection or resource over HTTP GET.
Describe returned data and generate its API schema.
Apply authentication, authorization, or other shared logic.
Customize generated API documentation.
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.
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.
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.
FastAPIAPIRoutergetpostPath Operation Configurationresponse_modelDepends