forked from cyclic-software/starter-fastapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
35 lines (21 loc) · 637 Bytes
/
app.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
from fastapi import FastAPI
from fastapi.responses import FileResponse
from pydantic import BaseModel
app = FastAPI()
class Item(BaseModel):
item_id: int
@app.get("/")
async def root():
return {"message": "Hello World"}
@app.get('/favicon.ico', include_in_schema=False)
async def favicon():
return FileResponse('favicon.ico')
@app.get("/item/{item_id}")
async def read_item(item_id: int):
return {"item_id": item_id}
@app.get("/items/")
async def list_items():
return [{"item_id": 1, "name": "Foo"}, {"item_id": 2, "name": "Bar"}]
@app.post("/items/")
async def create_item(item: Item):
return item