todo_data = {
1: {
"id": 1,
"contents": "실전 FastAPI 섹션 0 수강",
"is_done": True,
},
2: {
"id": 2,
"contents": "실전 FastAPI 섹션 1 수강",
"is_done": False,
},
3: {
"id": 3,
"contents": "실전 FastAPI 섹션 2 수강",
"is_done": False,
}
}
# todo_id를 path로 사용
@app.get("/todos/{todo_id}")
def get_todo_handler(todo_id: int):
# todo_id를 받고 만약 없는 값을 받는다면 {} 빈 dictionary 값으로 받기
return todo_data.get(todo_id, {})
swagger에 진입해서 todo_id에 1을 넣는다면

값이 없는 4번을 넣게 되면

'FastAPI > FastAPI 알아보기' 카테고리의 다른 글
| PATCH API - 수정 (0) | 2026.05.10 |
|---|---|
| POST API - 생성 (0) | 2026.05.10 |
| GET API - 전체 조회 (0) | 2026.05.10 |
| FastAPI 간단한 HTTP 통신 (0) | 2026.05.10 |
| FastAPI 소개 (0) | 2026.05.09 |