Handling cookies
- 4th Feb 2023
Send cookies
from fastapi import Response
from fastapi import Cookie
.
.
.
@router.get('/send-cookies/')
async def send_cookies(response: Response):
response.set_cookie(key='my_cookie', value='the content of my cookie')
return 'Ok'
Read cookies
from fastapi import Response
from fastapi import Cookie
.
.
.
@router.get('/get-cookies/')
async def get_cookies(my_cookie: str = Cookie(None)):
print(my_cookie)
return 'Ok'
Thanks for reading :)
I invite you to continue reading other entries and visiting us again soon.
Related Posts:
- 2nd Feb 2023
- 3rd Feb 2023
- 3rd Feb 2023
- 4th Feb 2023
- 4th Feb 2023
- 4th Feb 2023
- 4th Feb 2023
- 4th Feb 2023
- 5th Feb 2023