post() — fastapi Function Reference
Architecture documentation for the post() function in routing.py from the fastapi codebase.
Entity Profile
Dependency Diagram
graph TD 12dce19e_74a0_f6cd_7c8f_689f6d3bd491["post()"] ecadd3bc_0c58_b4e5_06d8_57da79199adc["APIRouter"] 12dce19e_74a0_f6cd_7c8f_689f6d3bd491 -->|defined in| ecadd3bc_0c58_b4e5_06d8_57da79199adc 2d8f2368_f214_e28c_d224_5dd3affead89["post()"] 2d8f2368_f214_e28c_d224_5dd3affead89 -->|calls| 12dce19e_74a0_f6cd_7c8f_689f6d3bd491 fbb5c527_c628_1375_0b4b_0dc27f28dba6["__init__()"] fbb5c527_c628_1375_0b4b_0dc27f28dba6 -->|calls| 12dce19e_74a0_f6cd_7c8f_689f6d3bd491 151590c8_e931_55e7_3262_5eca3d623171["test_top_level_generate_unique_id()"] 151590c8_e931_55e7_3262_5eca3d623171 -->|calls| 12dce19e_74a0_f6cd_7c8f_689f6d3bd491 4fd33aaf_fe3e_7115_3638_8d3a4c4e1b68["test_router_overrides_generate_unique_id()"] 4fd33aaf_fe3e_7115_3638_8d3a4c4e1b68 -->|calls| 12dce19e_74a0_f6cd_7c8f_689f6d3bd491 b5d0d990_bd82_76ac_e2e3_5f9bb785fbaf["test_router_include_overrides_generate_unique_id()"] b5d0d990_bd82_76ac_e2e3_5f9bb785fbaf -->|calls| 12dce19e_74a0_f6cd_7c8f_689f6d3bd491 191b6bb7_4a31_fd3c_3847_5c272456515b["test_subrouter_top_level_include_overrides_generate_unique_id()"] 191b6bb7_4a31_fd3c_3847_5c272456515b -->|calls| 12dce19e_74a0_f6cd_7c8f_689f6d3bd491 e4f92ec3_d858_c656_b001_95da4b92075d["test_router_path_operation_overrides_generate_unique_id()"] e4f92ec3_d858_c656_b001_95da4b92075d -->|calls| 12dce19e_74a0_f6cd_7c8f_689f6d3bd491 eb833757_871a_0105_e42d_92e668ad2f4f["test_app_path_operation_overrides_generate_unique_id()"] eb833757_871a_0105_e42d_92e668ad2f4f -->|calls| 12dce19e_74a0_f6cd_7c8f_689f6d3bd491 91fd33e1_c0c1_95bb_17af_05ea3f6c797c["test_callback_override_generate_unique_id()"] 91fd33e1_c0c1_95bb_17af_05ea3f6c797c -->|calls| 12dce19e_74a0_f6cd_7c8f_689f6d3bd491 be5a27db_5cd5_b4da_ccfd_df3b0b032427["test_warn_duplicate_operation_id()"] be5a27db_5cd5_b4da_ccfd_df3b0b032427 -->|calls| 12dce19e_74a0_f6cd_7c8f_689f6d3bd491 071a9251_91a6_7b3a_366d_21d88bf197ec["test_invalid_method_doesnt_match()"] 071a9251_91a6_7b3a_366d_21d88bf197ec -->|calls| 12dce19e_74a0_f6cd_7c8f_689f6d3bd491 d456e5c1_545c_7095_5b60_6234486c9d91["test_invalid_path_doesnt_match()"] d456e5c1_545c_7095_5b60_6234486c9d91 -->|calls| 12dce19e_74a0_f6cd_7c8f_689f6d3bd491 6a8dad5e_61e5_8086_e2a6_e7db4a0c2ceb["api_route()"] 12dce19e_74a0_f6cd_7c8f_689f6d3bd491 -->|calls| 6a8dad5e_61e5_8086_e2a6_e7db4a0c2ceb style 12dce19e_74a0_f6cd_7c8f_689f6d3bd491 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
fastapi/routing.py lines 2268–2648
def post(
self,
path: Annotated[
str,
Doc(
"""
The URL path to be used for this *path operation*.
For example, in `http://example.com/items`, the path is `/items`.
"""
),
],
*,
response_model: Annotated[
Any,
Doc(
"""
The type to use for the response.
It could be any valid Pydantic *field* type. So, it doesn't have to
be a Pydantic model, it could be other things, like a `list`, `dict`,
etc.
It will be used for:
* Documentation: the generated OpenAPI (and the UI at `/docs`) will
show it as the response (JSON Schema).
* Serialization: you could return an arbitrary object and the
`response_model` would be used to serialize that object into the
corresponding JSON.
* Filtering: the JSON sent to the client will only contain the data
(fields) defined in the `response_model`. If you returned an object
that contains an attribute `password` but the `response_model` does
not include that field, the JSON sent to the client would not have
that `password`.
* Validation: whatever you return will be serialized with the
`response_model`, converting any data as necessary to generate the
corresponding JSON. But if the data in the object returned is not
valid, that would mean a violation of the contract with the client,
so it's an error from the API developer. So, FastAPI will raise an
error and return a 500 error code (Internal Server Error).
Read more about it in the
[FastAPI docs for Response Model](https://fastapi.tiangolo.com/tutorial/response-model/).
"""
),
] = Default(None),
status_code: Annotated[
Optional[int],
Doc(
"""
The default status code to be used for the response.
You could override the status code by returning a response directly.
Read more about it in the
[FastAPI docs for Response Status Code](https://fastapi.tiangolo.com/tutorial/response-status-code/).
"""
),
] = None,
tags: Annotated[
Optional[list[Union[str, Enum]]],
Doc(
"""
A list of tags to be applied to the *path operation*.
It will be added to the generated OpenAPI (e.g. visible at `/docs`).
Read more about it in the
[FastAPI docs for Path Operation Configuration](https://fastapi.tiangolo.com/tutorial/path-operation-configuration/#tags).
"""
),
] = None,
dependencies: Annotated[
Optional[Sequence[params.Depends]],
Doc(
"""
A list of dependencies (using `Depends()`) to be applied to the
*path operation*.
Read more about it in the
Domain
Subdomains
Defined In
Called By
- __init__()
- post()
- test_app_path_operation_overrides_generate_unique_id()
- test_callback_override_generate_unique_id()
- test_invalid_method_doesnt_match()
- test_invalid_path_doesnt_match()
- test_router_include_overrides_generate_unique_id()
- test_router_overrides_generate_unique_id()
- test_router_path_operation_overrides_generate_unique_id()
- test_subrouter_top_level_include_overrides_generate_unique_id()
- test_top_level_generate_unique_id()
- test_warn_duplicate_operation_id()
Source
Frequently Asked Questions
What does post() do?
post() is a function in the fastapi codebase, defined in fastapi/routing.py.
Where is post() defined?
post() is defined in fastapi/routing.py at line 2268.
What does post() call?
post() calls 3 function(s): Default, api_route, include_router.
What calls post()?
post() is called by 12 function(s): __init__, post, test_app_path_operation_overrides_generate_unique_id, test_callback_override_generate_unique_id, test_invalid_method_doesnt_match, test_invalid_path_doesnt_match, test_router_include_overrides_generate_unique_id, test_router_overrides_generate_unique_id, and 4 more.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free