| 1 |
from litestar import Litestar, Response, get |
| 2 |
from litestar.datastructures import Cookie |
| 3 |
|
| 4 |
|
| 5 |
@get("/static", response_cookies=[Cookie(key="my-cookie", value="cookie-value")]) |
| 6 |
async def static_cookie() -> dict[str, str]: |
| 7 |
return {"set": "static"} |
| 8 |
|
| 9 |
|
| 10 |
@get("/dynamic") |
| 11 |
async def dynamic_cookie() -> Response[dict[str, str]]: |
| 12 |
return Response( |
| 13 |
{"set": "dynamic"}, |
| 14 |
cookies=[Cookie(key="my-cookie", value="cookie-value")], |
| 15 |
) |
| 16 |
|
| 17 |
|
| 18 |
app = Litestar(route_handlers=[static_cookie, dynamic_cookie]) |