forked from NimbleBoxAI/nbox-specimens
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
44 lines (39 loc) · 905 Bytes
/
server.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
42
43
44
from fastapi import FastAPI, Response
app = FastAPI()
ITEMS = {
"foo": "The Foo Wrestlers",
"bar": "The Bar Fighters",
"wysiwyg": "What You See Is What You Get",
"memes": "Memes are the best",
"fastapi": "FastAPI is a server",
}
@app.get("/")
def read_root():
return {
"message": "Hello World!"
}
@app.get("/items/{item_id}")
def read_item(item_id: str, resp: Response):
if item_id in ITEMS:
return {
"item_id": item_id,
"item_name": ITEMS[item_id]
}
else:
resp.status_code = 404
return {
"message": "Item not found"
}
@app.post("/update_item_details")
def update_item_details(item_id: str, item_name: str, resp: Response):
if item_id in ITEMS:
ITEMS[item_id] = item_name
return {
"item_id": item_id,
"item_name": item_name
}
else:
resp.status_code = 404
return {
"message": "Item not found"
}