Skip to content

📨 🍪

⚙️ Response 🔢

👆 💪 📣 🔢 🆎 Response 👆 ➡ 🛠️ 🔢.

& ⤴️ 👆 💪 ⚒ 🍪 👈 🔀 📨 🎚.

from fastapi import FastAPI, Response

app = FastAPI()


@app.post("/cookie-and-object/")
def create_cookie(response: Response):
    response.set_cookie(key="fakesession", value="fake-cookie-session-value")
    return {"message": "Come to the dark side, we have cookies"}

& ⤴️ 👆 💪 📨 🙆 🎚 👆 💪, 👆 🛎 🔜 ( dict, 💽 🏷, ♒️).

& 🚥 👆 📣 response_model, ⚫️ 🔜 ⚙️ ⛽ & 🗜 🎚 👆 📨.

FastAPI 🔜 ⚙️ 👈 🔀 📨 ⚗ 🍪 (🎚 & 👔 📟), & 🔜 🚮 👫 🏁 📨 👈 🔌 💲 👆 📨, ⛽ 🙆 response_model.

👆 💪 📣 Response 🔢 🔗, & ⚒ 🍪 (& 🎚) 👫.

📨 Response 🔗

👆 💪 ✍ 🍪 🕐❔ 🛬 Response 🔗 👆 📟.

👈, 👆 💪 ✍ 📨 🔬 📨 📨 🔗.

⤴️ ⚒ 🍪 ⚫️, & ⤴️ 📨 ⚫️:

from fastapi import FastAPI
from fastapi.responses import JSONResponse

app = FastAPI()


@app.post("/cookie/")
def create_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")
    return response

Tip

✔️ 🤯 👈 🚥 👆 📨 📨 🔗 ↩️ ⚙️ Response 🔢, FastAPI 🔜 📨 ⚫️ 🔗.

, 👆 🔜 ✔️ ⚒ 💭 👆 💽 ☑ 🆎. 🤶 Ⓜ. ⚫️ 🔗 ⏮️ 🎻, 🚥 👆 🛬 JSONResponse.

& 👈 👆 🚫 📨 🙆 📊 👈 🔜 ✔️ ⛽ response_model.

🌅 ℹ

📡 ℹ

👆 💪 ⚙️ from starlette.responses import Response ⚖️ from starlette.responses import JSONResponse.

FastAPI 🚚 🎏 starlette.responses fastapi.responses 🏪 👆, 👩‍💻. ✋️ 🌅 💪 📨 👟 🔗 ⚪️➡️ 💃.

& Response 💪 ⚙️ 🛎 ⚒ 🎚 & 🍪, FastAPI 🚚 ⚫️ fastapi.Response.

👀 🌐 💪 🔢 & 🎛, ✅ 🧾 💃.