FastAPI: Reading Request Cookies
FastAPI treats request cookies like any other parameter. Declare them directly in your endpoint's function signature using `Cookie()`, and the framework will extract the value for you. Use this for reading session IDs or user preferences.
FastAPI treats request cookies as first-class parameters, just like from the path or query string. You declare them directly in your endpoint's function signature using `Cookie()`, and FastAPI handles parsing the request headers for you. This is ideal for accessing session tokens, tracking IDs, or user preferences. The main footgun is confusing this with *setting* cookies—`Cookie()` is for input only; setting them happens on the response object.
Read the original → fastapi.tiangolo.com
- #python
- #fastapi
- #web
- #api
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.