Ojasa Mirai

Ojasa Mirai

FastAPI

Loading...

Learning Level

🟢 Beginner🔵 Advanced
🚀 What is FastAPI📚 Creating Your First API📚 Running the Server📚 HTTP Methods📚 API Endpoints📚 Request and Response📚 Documentation📚 Testing Basics
Fastapi/Api Basics/Running Server

Running the Server âš¡

Now that you've written your API code, you need to run it. FastAPI uses Uvicorn, an ASGI server, to run your application.

Installation

pip install fastapi uvicorn

Starting the Server

Create 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 --reload

What This Does

  • `uvicorn`: The ASGI server
  • `main`: Your Python file
  • `app`: The FastAPI instance
  • `--reload`: Auto-restart on code changes

Server Output

INFO:     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 complete

Accessing Your API

1. 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`

Making Requests

Using curl:

curl http://localhost:8000/

Using Python:

import httpx

response = httpx.get("http://localhost:8000/")
print(response.json())

Common Issues

Port already in use:

uvicorn main:app --port 8001

Module not found:

pip install fastapi uvicorn

Changes not reflecting:

  • Ensure `--reload` is enabled
  • Check for syntax errors

🔑 Key Takeaways

  • ✅ Use `uvicorn` to run FastAPI applications
  • ✅ `--reload` enables development mode
  • ✅ Visit `/docs` for interactive testing
  • ✅ Default port is 8000
  • ✅ Can change port with `--port`

Resources

Python Docs

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

Courses

PythonFastapiReactJSCloud

© 2026 Ojasa Mirai. All rights reserved.

TwitterGitHubLinkedIn