FastAPI 요청 메서드 로직 - 05

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

1. CRUD Operations

  • Create - 생성
  • Read - 호출
  • Update - 업데이트
  • Delete - 삭제

 

2. Use HTTP Request Method

  • GET - 호출
  • PUT - 업데이트
  • POST - 생성
  • DELETE - 삭제

ex) book

  • GET - get all the books
  • PUT - Update book
  • POST - Create new book
  • DELETE - Delete book

 

3. 딕셔너리 만들어서 GET 호출하기

 

from fastapi import FastAPI

app = FastAPI()


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'},

}


@app.get("/")
async def read_all_books():
    return BOOKS
  • docs에 접속 후 API 결과 확인
728x90
SMALL
저작자표시 비영리 변경금지 (새창열림)

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

FastAPI Path Parameters(추가) - 07  (0) 2022.12.21
FastAPI Path Parameters(열거형) - 06  (0) 2022.12.21
FastAPI Swagger / HTTP 데코레이터 - 04  (0) 2022.12.21
FastAPI - Swagger, HTTP 요청 관련 - 03  (0) 2022.12.20
FastAPI 설정 및 설치 - 02  (0) 2022.12.20
'Develop/FastAPI' 카테고리의 다른 글
  • FastAPI Path Parameters(추가) - 07
  • FastAPI Path Parameters(열거형) - 06
  • FastAPI Swagger / HTTP 데코레이터 - 04
  • FastAPI - Swagger, HTTP 요청 관련 - 03
동석해요
동석해요
공부하고 싶은게 많은, 사소한 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 요청 메서드 로직 - 05
상단으로

티스토리툴바