Develop/FastAPI
FastAPI Delete Request - 11
김잠봉
2022. 12. 22. 09:20
728x90
1. Delete
- 데이터 삭제
2. 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'},
}
3. 함수 정의
- @app.delete
- book_name을 받아서 BOOKS의 키 값으로 제거
@app.delete("/{book_name}")
async def delete_book(book_name):
del BOOKS[book_name]
return f"Book {book_name} deleted."


-
- BOOKS의 book_2의 키와 값이 없어진 BOOKS return
728x90
SMALL