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
|
|
|
```
|
|
|
|
|
|
|
|
|
|
!!! info
|
|
|
|
|
`Cookie` is a "sister" class of `Path` and `Query`. It also inherits from the same common `Param` class.
|
|
|
|
|
|
|
|
|
|
!!! 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`.
|