new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

FastAPI · all subjects

path operations & decorators

12 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Status code import options

Status codes can be imported from either starlette.status or fastapi.status. FastAPI provides the same Starlette status codes via fastapi.status as a convenience, but they come directly from Starlette.

Tags with Enums

FastAPI supports using Enum for tags in the same way as simple strings. This is useful for large applications to ensure related path operations always use the same tag without duplication.

Summary and description parameters

You can add a summary and description to a path operation by passing summary and description parameters to the path operation decorator.

Response description parameter

You can describe the response with the response_description parameter. This parameter specifically refers to the response, while description refers generally to the path operation.

Deprecated parameter for path operations

You can mark a path operation as deprecated without removing it by adding the deprecated parameter set to True to the path operation decorator. Deprecated path operations are displayed as deprecated in the interactive documentation.

Path operation decorator parameters configuration

Path operation decorators accept several parameters for configuration. These parameters are passed directly to the path operation decorator, not to the path operation function itself.

Response status code parameter in path operations

You can define the HTTP status code to be used in the response of a path operation by passing the status_code parameter to the decorator. You can pass the int code directly (like 404) or use shortcut constants from fastapi.status or starlette.status. The status code will be added to the OpenAPI schema.

Tags parameter for path operations

You can add tags to a path operation by passing the tags parameter with a list of strings. Tags are added to the OpenAPI schema and used by automatic documentation interfaces. FastAPI also supports passing tags as an Enum for managing multiple tags consistently across related path operations.

Summary and description parameters in path operations

You can add summary and description parameters to path operation decorators to provide metadata about the operation that appears in the OpenAPI schema and documentation.

Description from docstring in path operations

You can declare a path operation description in the function docstring (a multi-line string as the first expression inside a function). FastAPI will read the description from the docstring and display it in interactive docs. Markdown can be written in the docstring and will be interpreted and displayed correctly.

Response description parameter

You can specify the response description using the response_description parameter in the path operation decorator. This parameter refers specifically to the response description, whereas the description parameter refers to the path operation in general. OpenAPI specifies that each path operation requires a response description, so if you don't provide one, FastAPI will automatically generate 'Successful response'.

Deprecate a path operation

You can mark a path operation as deprecated by passing the deprecated parameter to the decorator. This marks the operation as deprecated in the interactive docs without removing it from the API.

Give your agent this brain