mirror of
https://github.com/fastapi/fastapi.git
synced 2026-01-23 21:42:16 -05:00
* Updated .py files with Optional tag (up to body_nested_models) * Update optionals * docs_src/ all updates, few I was unsure of * Updated markdown files with Optional param * es: Add Optional typing to index.md * Last of markdown files updated with Optional param * Update highlight lines * it: Add Optional typings * README.md: Update with Optional typings * Update more highlight increments * Update highlights * schema-extra-example.md: Update highlights * updating highlighting on website to reflect .py changes * Update highlighting for query-params & response-directly * Address PR comments * Get rid of unnecessary comment * ⏪ Revert Optional in Chinese docs as it probably also requires changes in text * 🎨 Apply format * ⏪ Revert modified example * ♻️ Simplify example in docs * 📝 Update OpenAPI callback example to use Optional * ✨ Add Optional types to tests * 📝 Update docs about query params, default to using Optional * 🎨 Update code examples line highlighting * 📝 Update nested models docs to use "type parameters" instead of "subtypes" * 📝 Add notes about FastAPI usage of None including: = None and = Query(None) and clarify relationship with Optional[str] * 📝 Add note about response_model_by_alias * ♻️ Simplify query param list example * 🔥 Remove test for removed example * ✅ Update test for updated example Co-authored-by: Christopher Nguyen <chrisngyn99@gmail.com> Co-authored-by: yk396 <yk396@cornell.edu> Co-authored-by: Kai Chen <kaichen120@gmail.com>
1.0 KiB
1.0 KiB
Cookie Parameters
You can define Cookie parameters the same way you define Query and Path parameters.
Import Cookie
First import Cookie:
{!../../../docs_src/cookie_params/tutorial001.py!}
Declare Cookie parameters
Then declare the cookie parameters using the same structure as with Path and Query.
The first value is the default value, you can pass all the extra validation or annotation parameters:
{!../../../docs_src/cookie_params/tutorial001.py!}
!!! note "Technical Details"
Cookie is a "sister" class of Path and Query. It also inherits from the same common Param class.
But remember that when you import `Query`, `Path`, `Cookie` and others from `fastapi`, those are actually functions that return special classes.
!!! info
To declare cookies, you need to use Cookie, because otherwise the parameters would be interpreted as query parameters.
Recap
Declare cookies with Cookie, using the same common pattern as Query and Path.