-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
44 lines (27 loc) · 791 Bytes
/
main.py
File metadata and controls
44 lines (27 loc) · 791 Bytes
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 typing import List
from fastapi import FastAPI, HTTPException, Query, Body
from pydantic import BaseModel
app = FastAPI()
class Item(BaseModel):
text: str = None
is_there: bool = False
items = []
@app.get("/")
def root():
return {"Hello, Beautiful World"}
@app.post("/item")
def post_an_item(item: List[Item] = Body([])):
items.extend(item)
return items
@app.get("/items")
def get_all_items():
return items
@app.get("/items/{item_id}", response_model=Item)
def get_a_single(item_id: int) -> Item:
if item_id < len(items):
return items[item_id]
else:
raise HTTPException(status_code=404, detail=f"Item with ID {item_id} not found")
@app.get("/items")
def get_a_multiple(something: int = 10):
return items[0:something]