2018-12-29 18:43:58 +04:00
You can define Cookie parameters the same way you define `Query` and `Path` parameters.
2018-12-14 20:44:42 +04:00
## Import `Cookie`
First import `Cookie` :
```Python hl_lines="1"
2018-12-21 16:22:33 +04:00
{!./src/cookie_params/tutorial001.py!}
2018-12-14 20:44:42 +04:00
` ``
2018-12-29 18:43:58 +04:00
## Declare ` Cookie` parameters
2018-12-14 20:44:42 +04:00
Then declare the cookie parameters using the same structure as with ` Path` and ` Query`.
2018-12-29 18:43:58 +04:00
The first value is the default value, you can pass all the extra validation or annotation parameters:
2018-12-14 20:44:42 +04:00
` ``Python hl_lines="7"
2018-12-21 16:22:33 +04:00
{!./src/cookie_params/tutorial001.py!}
2018-12-14 20:44:42 +04:00
` ``
2019-05-15 22:01:23 +04:00
!!! note "Technical Details"
2018-12-14 20:44:42 +04:00
` Cookie` is a "sister" class of ` Path` and ` Query`. It also inherits from the same common ` Param` class.
2019-05-15 22:01:23 +04:00
But remember that when you import ` Query`, ` Path`, ` Cookie` and others from ` fastapi`, <a href="https://fastapi.tiangolo.com/tutorial/path-params-numeric-validations/#recap" target="_blank">those are actually functions that return classes of the same name</a>.
2018-12-14 20:44:42 +04:00
!!! info
2018-12-29 18:43:58 +04:00
To declare cookies, you need to use ` Cookie`, because otherwise the parameters would be interpreted as query parameters.
2018-12-14 20:44:42 +04:00
## Recap
Declare cookies with ` Cookie`, using the same common pattern as ` Query` and ` Path`.