개발로 자기계발
article thumbnail
728x90

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
profile

개발로 자기계발

@김잠봉

틀린부분이나 조언이 있다면 언제든 환영입니다:-)