-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMultipleParameters.py
45 lines (38 loc) · 1001 Bytes
/
MultipleParameters.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
45
from fastapi import FastAPI, Query, Path
from fastapi.middleware.cors import CORSMiddleware
import nest_asyncio
from pyngrok import ngrok
import uvicorn
from pydantic import BaseModel
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=['*'],
allow_credentials=True,
allow_methods=['*'],
allow_headers=['*'],
)
@app.get('/')
async def root():
return {'hello': 'world'}
class Item(BaseModel):
name: str
description: str = None
price: float
tax: float = None
async def update_item(
*,
item_id: int = Path(..., title="The ID of the item to get", ge=0, le=1000), # Path Parameter
q: str = None, # Query Paramter
item: Item = None, # Request Body
):
results = {"item_id": item_id}
if q:
results.update({"q": q})
if item:
results.update({"item": item})
return results
ngrok_tunnel = ngrok.connect(8000)
print('Public URL:', ngrok_tunnel.public_url)
nest_asyncio.apply()
uvicorn.run(app, port=8000)