
FastAPI
Now that you've written your API code, you need to run it. FastAPI uses Uvicorn, an ASGI server, to run your application.
pip install fastapi uvicornCreate a file called `main.py`:
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
async def root():
return {"message": "Hello, World!"}Run it:
uvicorn main:app --reloadINFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO: Started server process [12345]
INFO: Waiting for application startup.
INFO: Application startup complete1. Browser: Visit `http://localhost:8000`
2. Interactive Docs: Visit `http://localhost:8000/docs`
3. Alternative Docs: Visit `http://localhost:8000/redoc`
4. API Schema: Visit `http://localhost:8000/openapi.json`
Using curl:
curl http://localhost:8000/Using Python:
import httpx
response = httpx.get("http://localhost:8000/")
print(response.json())Port already in use:
uvicorn main:app --port 8001Module not found:
pip install fastapi uvicornChanges not reflecting:
Resources
Ojasa Mirai
Master AI-powered development skills through structured learning, real projects, and verified credentials. Whether you're upskilling your team or launching your career, we deliver the skills companies actually need.
Learn Deep • Build Real • Verify Skills • Launch Forward