Skip to content

📨 👔 📟

🎏 🌌 👆 💪 ✔ 📨 🏷, 👆 💪 📣 🇺🇸🔍 👔 📟 ⚙️ 📨 ⏮️ 🔢 status_code 🙆 ➡ 🛠️:

  • @app.get()
  • @app.post()
  • @app.put()
  • @app.delete()
  • ♒️.
from fastapi import FastAPI

app = FastAPI()


@app.post("/items/", status_code=201)
async def create_item(name: str):
    return {"name": name}

Note

👀 👈 status_code 🔢 "👨‍🎨" 👩‍🔬 (get, post, ♒️). 🚫 👆 ➡ 🛠️ 🔢, 💖 🌐 🔢 & 💪.

status_code 🔢 📨 🔢 ⏮️ 🇺🇸🔍 👔 📟.

Info

status_code 💪 👐 📨 IntEnum, ✅ 🐍 http.HTTPStatus.

⚫️ 🔜:

  • 📨 👈 👔 📟 📨.
  • 📄 ⚫️ ✅ 🗄 🔗 ( & , 👩‍💻 🔢):

Note

📨 📟 (👀 ⏭ 📄) 🎦 👈 📨 🔨 🚫 ✔️ 💪.

FastAPI 💭 👉, & 🔜 🏭 🗄 🩺 👈 🇵🇸 📤 🙅‍♂ 📨 💪.

🔃 🇺🇸🔍 👔 📟

Note

🚥 👆 ⏪ 💭 ⚫️❔ 🇺🇸🔍 👔 📟, 🚶 ⏭ 📄.

🇺🇸🔍, 👆 📨 🔢 👔 📟 3️⃣ 9️⃣ 🍕 📨.

👫 👔 📟 ✔️ 📛 🔗 🤔 👫, ✋️ ⚠ 🍕 🔢.

📏:

  • 100 & 🔛 "ℹ". 👆 🛎 ⚙️ 👫 🔗. 📨 ⏮️ 👫 👔 📟 🚫🔜 ✔️ 💪.
  • 200 & 🔛 "🏆" 📨. 👫 🕐 👆 🔜 ⚙️ 🏆.
    • 200 🔢 👔 📟, ❔ ⛓ 🌐 "👌".
    • ➕1️⃣ 🖼 🔜 201, "✍". ⚫️ 🛎 ⚙️ ⏮️ 🏗 🆕 ⏺ 💽.
    • 🎁 💼 204, "🙅‍♂ 🎚". 👉 📨 ⚙️ 🕐❔ 📤 🙅‍♂ 🎚 📨 👩‍💻, & 📨 🔜 🚫 ✔️ 💪.
  • 300 & 🔛 "❎". 📨 ⏮️ 👫 👔 📟 5️⃣📆 ⚖️ 5️⃣📆 🚫 ✔️ 💪, 🌖 304, "🚫 🔀", ❔ 🔜 🚫 ✔️ 1️⃣.
  • 400 & 🔛 "👩‍💻 ❌" 📨. 👫 🥈 🆎 👆 🔜 🎲 ⚙️ 🏆.
    • 🖼 404, "🚫 🔎" 📨.
    • 💊 ❌ ⚪️➡️ 👩‍💻, 👆 💪 ⚙️ 400.
  • 500 & 🔛 💽 ❌. 👆 🌖 🙅 ⚙️ 👫 🔗. 🕐❔ 🕳 🚶 ❌ 🍕 👆 🈸 📟, ⚖️ 💽, ⚫️ 🔜 🔁 📨 1️⃣ 👫 👔 📟.

Tip

💭 🌅 🔃 🔠 👔 📟 & ❔ 📟 ⚫️❔, ✅ 🏇 🧾 🔃 🇺🇸🔍 👔 📟.

⌨ 💭 📛

➡️ 👀 ⏮️ 🖼 🔄:

from fastapi import FastAPI

app = FastAPI()


@app.post("/items/", status_code=201)
async def create_item(name: str):
    return {"name": name}

201 👔 📟 "✍".

✋️ 👆 🚫 ✔️ ✍ ⚫️❔ 🔠 👉 📟 ⛓.

👆 💪 ⚙️ 🏪 🔢 ⚪️➡️ fastapi.status.

from fastapi import FastAPI, status

app = FastAPI()


@app.post("/items/", status_code=status.HTTP_201_CREATED)
async def create_item(name: str):
    return {"name": name}

👫 🏪, 👫 🧑‍🤝‍🧑 🎏 🔢, ✋️ 👈 🌌 👆 💪 ⚙️ 👨‍🎨 📋 🔎 👫:

📡 ℹ

👆 💪 ⚙️ from starlette import status.

FastAPI 🚚 🎏 starlette.status fastapi.status 🏪 👆, 👩‍💻. ✋️ ⚫️ 👟 🔗 ⚪️➡️ 💃.

🔀 🔢

⏪, 🏧 👩‍💻 🦮, 👆 🔜 👀 ❔ 📨 🎏 👔 📟 🌘 🔢 👆 📣 📥.