pythonasyncioapiasyncfastapiframeworkjsonjson-schemaopenapiopenapi3pydanticpython-typespython3redocreststarletteswaggerswagger-uiuvicornweb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1.1 KiB
1.1 KiB
You can define Cookie parameters the same way you define Query
and Path
parameters.
Import Cookie
First import Cookie
:
{!./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:
{!./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`, <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>.
!!! 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
.