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/Documentation

Automatic Documentation 📖

FastAPI automatically generates interactive API documentation from your code. No extra work needed!

Interactive Documentation

Visit `http://localhost:8000/docs` while your server is running.

You can:

  • See all endpoints
  • View request/response schemas
  • Try endpoints directly
  • See example requests/responses

Alternative Documentation

Visit `http://localhost:8000/redoc` for an alternative documentation view.

OpenAPI Schema

Visit `http://localhost:8000/openapi.json` to see the raw OpenAPI specification as JSON.

Customizing Documentation

Add descriptions to your endpoints:

@app.get("/items/{item_id}")
async def get_item(item_id: int):
    '''Get a specific item by ID.

    Args:
        item_id: The ID of the item to retrieve

    Returns:
        The item details
    '''
    return {"id": item_id}

Adding Examples

from pydantic import BaseModel

class Item(BaseModel):
    name: str
    price: float

    class Config:
        schema_extra = {
            "example": {
                "name": "Laptop",
                "price": 999.99
            }
        }

Customizing API Info

app = FastAPI(
    title="My API",
    description="This is my awesome API",
    version="1.0.0",
    docs_url="/api/docs",
    redoc_url="/api/redoc",
)

Endpoint Metadata

@app.post(
    "/items",
    summary="Create Item",
    description="Create a new item in the database",
    tags=["items"],
    status_code=201
)
async def create_item(item: Item):
    return item

🔑 Key Takeaways

  • ✅ FastAPI auto-generates docs
  • ✅ Visit /docs for interactive UI
  • ✅ Visit /redoc for alternative view
  • ✅ /openapi.json has OpenAPI spec
  • ✅ Add docstrings for descriptions
  • ✅ Use examples in models
  • ✅ Tag endpoints for organization

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