Handling cookies

Notes Single

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: