빠른 성능
타입 힌트 기반의 선언형 문법
from fastapi import FastAPI
app = FastAPI()
@app.get("/hello")
def read_hello(name: str):
return {"message": f"Hello, {name}"}
자동 API 문서 생성
Pydantic 기반의 데이터 검증
비동기 처리 지원(astnc/await)
모듈화, 확장성
from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI()
class Item(BaseModel):
name: str
price: float
@app.post("/items/")
async def create_item(item: Item):
return {"item_name": item.name, "item_price": item.price}
이 코드는 /items/
로 POST 요청이 들어올 때 JSON 데이터를 Item
모델로 검증하고 응답하는 예입