fromfastapiimportFastAPI,Responseapp=FastAPI()@app.post("/cookie-and-object/")defcreate_cookie(response:Response):response.set_cookie(key="fakesession",value="fake-cookie-session-value")return{"message":"Come to the dark side, we have cookies"}
fromfastapiimportFastAPIfromfastapi.responsesimportJSONResponseapp=FastAPI()@app.post("/cookie/")defcreate_cookie():content={"message":"Come to the dark side, we have cookies"}response=JSONResponse(content=content)response.set_cookie(key="fakesession",value="fake-cookie-session-value")returnresponse