
FastAPI
FastAPI automatically generates interactive API documentation from your code. No extra work needed!
Visit `http://localhost:8000/docs` while your server is running.
You can:
Visit `http://localhost:8000/redoc` for an alternative documentation view.
Visit `http://localhost:8000/openapi.json` to see the raw OpenAPI specification as JSON.
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}from pydantic import BaseModel
class Item(BaseModel):
name: str
price: float
class Config:
schema_extra = {
"example": {
"name": "Laptop",
"price": 999.99
}
}app = FastAPI(
title="My API",
description="This is my awesome API",
version="1.0.0",
docs_url="/api/docs",
redoc_url="/api/redoc",
)@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 itemResources
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