-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtutorial.py
More file actions
32 lines (24 loc) · 772 Bytes
/
tutorial.py
File metadata and controls
32 lines (24 loc) · 772 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
from typing import Union
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def read_root():
return {"Hello": "World"}
# Path parameters
@app.get("/explorers/{explorer_id}")
async def getExplorer(explorer_id):
return {"explore_id": explorer_id}
# Query parameters
@app.get("/explorers")
async def getExplorer(limit: int = 4):
explorers = ["Dylan", "Caryn", "Jeevan", "Kevin", "Riaan", "Simon", "Ockie", "Ricardo", "Vallan", "Jaen", "Shephard"]
return explorers[:limit]
# Bonus: Request body
from pydantic import BaseModel
class Explorer(BaseModel):
name: str
jobTitle: str
@app.post("/explorers/")
async def createExplorer(explorer: Explorer):
# e.g. write code here to add the explorer to a database table...
return explorer