-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost_api.py
41 lines (31 loc) · 1.05 KB
/
post_api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from fastapi import FastAPI, Body
app = FastAPI()
books = [
{"title": "Title One", "author": "Author One", "category": "science"},
{"title": "Title Two", "author": "Author Two", "category": "Maths"},
{"title": "Title Three", "author": "Author Three", "category": "History"},
]
@app.post("/books/create_one")
def create_book(new_book=Body()):
books.append(new_book)
@app.get("/books")
def fetch_books():
return books
@app.post("/books/update_Book")
def update_book(update_book=Body()):
counter = 0
for book in books:
if book.get("title").casefold() == update_book.get("title").casefold():
book[counter] = update_book
return books[counter]
print(books[counter])
counter += 1
@app.patch("/books/patch_book")
def update_book(update_book=Body()):
counter = 0
for book in books:
if book.get("title").casefold() == update_book.get("title").casefold():
book[counter] = update_book
return books[counter]
# print(books[counter])
counter += 1