FastAPI Path Parameters(추가) - 07

2022. 12. 21. 14:55·Develop/FastAPI
728x90
SMALL

1. dictionary 정의

BOOKS = {
    'book_1': {'title':'Title One','author':'Author One'},
    'book_2': {'title':'Title Two','author':'Author Two'},
    'book_3': {'title': 'Title Three', 'author': 'Author Three'},
    'book_4': {'title': 'Title Four', 'author': 'Author Four'},
    'book_5': {'title': 'Title Five', 'author': 'Author Five'},
}

 

2. 함수 정의

  • 전체 BOOKS의 list를 볼 수 있음
@app.get("/")
async def read_all_books():
    return BOOKS
  • BOOKS의 1개의 키 값이 무조건 들어가야함
  • read_book의 매개변수에는 string만 들어갈 수 있음
@app.get("/{book_name}")
async def read_book(book_name: str):
    return BOOKS[book_name]
  • dictionary에 없는 키 값을 입력 시 에러
 
728x90
SMALL
저작자표시 비영리 변경금지 (새창열림)

'Develop > FastAPI' 카테고리의 다른 글

FastAPI Post Request - 09  (0) 2022.12.22
FastAPI Query Parameters - 08  (0) 2022.12.22
FastAPI Path Parameters(열거형) - 06  (0) 2022.12.21
FastAPI 요청 메서드 로직 - 05  (0) 2022.12.21
FastAPI Swagger / HTTP 데코레이터 - 04  (0) 2022.12.21
'Develop/FastAPI' 카테고리의 다른 글
  • FastAPI Post Request - 09
  • FastAPI Query Parameters - 08
  • FastAPI Path Parameters(열거형) - 06
  • FastAPI 요청 메서드 로직 - 05
동석해요
동석해요
공부하고 싶은게 많은, 사소한 IT 지식들 공유
    250x250
  • 동석해요
    개발로 자기계발
    동석해요
  • 전체
    오늘
    어제
    • 분류 전체보기 (226)
      • Develop (126)
        • 기초지식 (12)
        • FastAPI (102)
        • Django (11)
      • Database & Data (62)
        • 기초지식 (16)
        • MySQL (29)
        • PostgreSQL (8)
        • 데이터 분석 (9)
      • 인공지능 (11)
        • PyTorch (9)
      • Cloud (8)
        • AWS (4)
        • GCP (2)
      • 버그처리 (14)
      • 회고 & 일상 (5)
  • 인기 글

  • 최근 글

  • 최근 댓글

  • hELLO· Designed By정상우.v4.10.3
동석해요
FastAPI Path Parameters(추가) - 07
상단으로

티스토리툴바