Skip to content

🎧 🈸 - 🗻

🚥 👆 💪 ✔️ 2️⃣ 🔬 FastAPI 🈸, ⏮️ 👫 👍 🔬 🗄 & 👫 👍 🩺 ⚜, 👆 💪 ✔️ 👑 📱 & "🗻" 1️⃣ (⚖️ 🌅) 🎧-🈸(Ⓜ).

🗜 FastAPI 🈸

"🗜" ⛓ ❎ 🍕 "🔬" 🈸 🎯 ➡, 👈 ⤴️ ✊ 💅 🚚 🌐 🔽 👈 ➡, ⏮️ ➡ 🛠️ 📣 👈 🎧-🈸.

🔝-🎚 🈸

🥇, ✍ 👑, 🔝-🎚, FastAPI 🈸, & 🚮 ➡ 🛠️:

from fastapi import FastAPI

app = FastAPI()


@app.get("/app")
def read_main():
    return {"message": "Hello World from main app"}


subapi = FastAPI()


@subapi.get("/sub")
def read_sub():
    return {"message": "Hello World from sub API"}


app.mount("/subapi", subapi)

🎧-🈸

⤴️, ✍ 👆 🎧-🈸, & 🚮 ➡ 🛠️.

👉 🎧-🈸 ➕1️⃣ 🐩 FastAPI 🈸, ✋️ 👉 1️⃣ 👈 🔜 "🗻":

from fastapi import FastAPI

app = FastAPI()


@app.get("/app")
def read_main():
    return {"message": "Hello World from main app"}


subapi = FastAPI()


@subapi.get("/sub")
def read_sub():
    return {"message": "Hello World from sub API"}


app.mount("/subapi", subapi)

🗻 🎧-🈸

👆 🔝-🎚 🈸, app, 🗻 🎧-🈸, subapi.

👉 💼, ⚫️ 🔜 📌 ➡ /subapi:

from fastapi import FastAPI

app = FastAPI()


@app.get("/app")
def read_main():
    return {"message": "Hello World from main app"}


subapi = FastAPI()


@subapi.get("/sub")
def read_sub():
    return {"message": "Hello World from sub API"}


app.mount("/subapi", subapi)

✅ 🏧 🛠️ 🩺

🔜, 🏃 uvicorn ⏮️ 👑 📱, 🚥 👆 📁 main.py, ⚫️ 🔜:

$ uvicorn main:app --reload

<span style="color: green;">INFO</span>:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)

& 📂 🩺 http://127.0.0.1:8000/docs.

👆 🔜 👀 🏧 🛠️ 🩺 👑 📱, 🔌 🕴 🚮 👍 ➡ 🛠️:

& ⤴️, 📂 🩺 🎧-🈸, http://127.0.0.1:8000/subapi/docs.

👆 🔜 👀 🏧 🛠️ 🩺 🎧-🈸, ✅ 🕴 🚮 👍 ➡ 🛠️, 🌐 🔽 ☑ 🎧-➡ 🔡 /subapi:

🚥 👆 🔄 🔗 ⏮️ 🙆 2️⃣ 👩‍💻 🔢, 👫 🔜 👷 ☑, ↩️ 🖥 🔜 💪 💬 🔠 🎯 📱 ⚖️ 🎧-📱.

📡 ℹ: root_path

🕐❔ 👆 🗻 🎧-🈸 🔬 🔛, FastAPI 🔜 ✊ 💅 🔗 🗻 ➡ 🎧-🈸 ⚙️ 🛠️ ⚪️➡️ 🔫 🔧 🤙 root_path.

👈 🌌, 🎧-🈸 🔜 💭 ⚙️ 👈 ➡ 🔡 🩺 🎚.

& 🎧-🈸 💪 ✔️ 🚮 👍 📌 🎧-🈸 & 🌐 🔜 👷 ☑, ↩️ FastAPI 🍵 🌐 👉 root_pathⓂ 🔁.

👆 🔜 💡 🌅 🔃 root_path & ❔ ⚙️ ⚫️ 🎯 📄 🔃 ⛅ 🗳.