mirror of https://github.com/tiangolo/fastapi.git
📝 Add Cookie docs
This commit is contained in:
parent
76f2b67d38
commit
0d9519a771
|
|
@ -0,0 +1,29 @@
|
|||
You can define Cookie parameters the same way you define `Query` and `Path` parameteres.
|
||||
|
||||
## Import `Cookie`
|
||||
|
||||
First import `Cookie`:
|
||||
|
||||
```Python hl_lines="1"
|
||||
{!./tutorial/src/cookie-params/tutorial001.py!}
|
||||
```
|
||||
|
||||
## Declare `Cookie` parameteres
|
||||
|
||||
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 parameteres:
|
||||
|
||||
```Python hl_lines="7"
|
||||
{!./tutorial/src/cookie-params/tutorial001.py!}
|
||||
```
|
||||
|
||||
!!! info
|
||||
`Cookie` is a "sister" class of `Path` and `Query`. It also inherits from the same common `Param` class.
|
||||
|
||||
!!! info
|
||||
To declare cookies, you need to use `Cookie`, because otherwise the parameters would be interpreted as query parameteres.
|
||||
|
||||
## Recap
|
||||
|
||||
Declare cookies with `Cookie`, using the same common pattern as `Query` and `Path`.
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
from fastapi import Cookie, FastAPI
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
@app.get("/items/")
|
||||
async def read_items(*, ads_id: str = Cookie(None)):
|
||||
return {"ads_id": ads_id}
|
||||
|
|
@ -27,6 +27,7 @@ nav:
|
|||
- Body - Multiple Parameters: 'tutorial/body-multiple-params.md'
|
||||
- Body - Schema: 'tutorial/body-schema.md'
|
||||
- Body - Nested Models: 'tutorial/body-nested-models.md'
|
||||
- Cookie Parameters: 'tutorial/cookie-params.md'
|
||||
- Concurrency and async / await: 'async.md'
|
||||
- Deployment: 'deployment.md'
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue