📨 🎚¶
⚙️ Response
🔢¶
👆 💪 📣 🔢 🆎 Response
👆 ➡ 🛠️ 🔢 (👆 💪 🍪).
& ⤴️ 👆 💪 ⚒ 🎚 👈 🔀 📨 🎚.
from fastapi import FastAPI, Response
app = FastAPI()
@app.get("/headers-and-object/")
def get_headers(response: Response):
response.headers["X-Cat-Dog"] = "alone in the world"
return {"message": "Hello World"}
& ⤴️ 👆 💪 📨 🙆 🎚 👆 💪, 👆 🛎 🔜 ( dict
, 💽 🏷, ♒️).
& 🚥 👆 📣 response_model
, ⚫️ 🔜 ⚙️ ⛽ & 🗜 🎚 👆 📨.
FastAPI 🔜 ⚙️ 👈 🔀 📨 ⚗ 🎚 (🍪 & 👔 📟), & 🔜 🚮 👫 🏁 📨 👈 🔌 💲 👆 📨, ⛽ 🙆 response_model
.
👆 💪 📣 Response
🔢 🔗, & ⚒ 🎚 (& 🍪) 👫.
📨 Response
🔗¶
👆 💪 🚮 🎚 🕐❔ 👆 📨 Response
🔗.
✍ 📨 🔬 📨 📨 🔗 & 🚶♀️ 🎚 🌖 🔢:
from fastapi import FastAPI
from fastapi.responses import JSONResponse
app = FastAPI()
@app.get("/headers/")
def get_headers():
content = {"message": "Hello World"}
headers = {"X-Cat-Dog": "alone in the world", "Content-Language": "en-US"}
return JSONResponse(content=content, headers=headers)
📡 ℹ
👆 💪 ⚙️ from starlette.responses import Response
⚖️ from starlette.responses import JSONResponse
.
FastAPI 🚚 🎏 starlette.responses
fastapi.responses
🏪 👆, 👩💻. ✋️ 🌅 💪 📨 👟 🔗 ⚪️➡️ 💃.
& Response
💪 ⚙️ 🛎 ⚒ 🎚 & 🍪, FastAPI 🚚 ⚫️ fastapi.Response
.
🛃 🎚¶
✔️ 🤯 👈 🛃 © 🎚 💪 🚮 ⚙️ '✖-' 🔡.
✋️ 🚥 👆 ✔️ 🛃 🎚 👈 👆 💚 👩💻 🖥 💪 👀, 👆 💪 🚮 👫 👆 ⚜ 📳 (✍ 🌅 ⚜ (✖️-🇨🇳 ℹ 🤝)), ⚙️ 🔢 expose_headers
📄 💃 ⚜ 🩺.