null
vuild_
Nodes
Flows
Hubs
Login
MENU
GO
Notifications
Login
⌂
Python 웹 개발 입문 — FastAPI로 배우는 백엔드
Structure
intro
•
왜 Python으로 웹 백엔드를 만드는가?
•
FastAPI 개요 — 핵심 개념 정리
setup
•
FastAPI 개발 환경 구축
routing
•
FastAPI 라우팅과 경로 파라미터
project
•
FastAPI 미니 프로젝트 — Todo API
Flow Structure
왜 Python으로 웹 백엔드를 만드는가?
2 / 5
FastAPI 개발 환경 구축
☆ Star
↗ Full
FastAPI 개요 — 핵심 개념 정리
#fastapi
#python
#asgi
#pydantic
#overview
@devpc
|
2026-04-27 06:24:26
|
GET /api/v1/flows/16/nodes/276?fv=1&nv=1
Context:
Flow v1
→
Node v1
0
Views
1
Calls
# FastAPI 개요 — 핵심 개념 정리 ## FastAPI란? FastAPI는 Sebastian Ramírez가 2018년 만든 **Python 비동기 웹 프레임워크**입니다. Python의 타입 힌트 시스템을 최대로 활용하여 빠르고 안전한 API를 만들 수 있게 설계되었습니다. **GitHub Stars**: 70k+ (Django, Flask에 이어 Python 웹 프레임워크 3위) --- ## 아키텍처 이해 ``` 클라이언트 HTTP 요청 │ ▼ ASGI 서버 (uvicorn) ← 비동기 게이트웨이 인터페이스 │ ▼ Starlette (ASGI 앱) ← HTTP 라우팅, 미들웨어, WebSocket │ ▼ FastAPI (위에 레이어) ← 타입 힌트, Pydantic 통합, 의존성 주입 │ ▼ 라우트 핸들러 실행 ``` --- ## 핵심 컴포넌트 ### FastAPI 앱 인스턴스 ```python from fastapi import FastAPI app = FastAPI( title="My API", description="API 설명", version="1.0.0", ) ``` ### 라우터 ```python from fastapi import APIRouter router = APIRouter(prefix="/users", tags=["users"]) @router.get("/{user_id}") async def get_user(user_id: int): return {"id": user_id} app.include_router(router) ``` ### Pydantic 모델 데이터 검증과 직렬화의 핵심: ```python from pydantic import BaseModel, EmailStr, field_validator class UserCreate(BaseModel): username: str email: EmailStr age: int @field_validator('age') @classmethod def age_must_be_positive(cls, v): if v < 0: raise ValueError('나이는 0 이상이어야 합니다') return v class UserResponse(BaseModel): id: int username: str email: str model_config = {"from_attributes": True} # ORM 모드 ``` ### 의존성 주입 (Dependency Injection) ```python from fastapi import Depends, HTTPException from fastapi.security import OAuth2PasswordBearer oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token") async def get_current_user(token: str = Depends(oauth2_scheme)): user = verify_token(token) if not user: raise HTTPException(status_code=401, detail="Invalid token") return user @app.get("/me") async def read_me(current_user = Depends(get_current_user)): return current_user ``` --- ## HTTP 상태 코드 & 에러 처리 ```python from fastapi import HTTPException @app.get("/items/{item_id}") async def get_item(item_id: int): item = db.get(item_id) if not item: raise HTTPException( status_code=404, detail=f"Item {item_id} not found" ) return item ``` | 코드 | 의미 | 사용 상황 | |---|---|---| | 200 | OK | 기본 성공 | | 201 | Created | POST로 리소스 생성 | | 204 | No Content | DELETE 성공 | | 400 | Bad Request | 잘못된 요청 데이터 | | 401 | Unauthorized | 인증 필요 | | 403 | Forbidden | 권한 없음 | | 404 | Not Found | 리소스 없음 | | 422 | Unprocessable Entity | Pydantic 검증 실패 (자동) | | 500 | Internal Server Error | 서버 오류 |
왜 Python으로 웹 백엔드를 만드는가?
FastAPI 개발 환경 구축
// COMMENTS
Newest First
ON THIS PAGE
No content selected.