-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHearderParameters.py
41 lines (30 loc) · 1012 Bytes
/
HearderParameters.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
from fastapi import FastAPI,Header
from fastapi.middleware.cors import CORSMiddleware
import nest_asyncio
from pyngrok import ngrok
import uvicorn
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=['*'],
allow_credentials=True,
allow_methods=['*'],
allow_headers=['*'],
)
@app.get('/')
async def root():
return {'hello': 'world'}
## Hearder Class
@app.get("/items/")
async def read_items(*, ads_id: str = Header("abc")): ## Default Value
return {"ads_id": ads_id}
@app.get("/itemsOne/")
async def read_items(*, user_agent: str = Header(None)): ## Optional
return {"User-Agent": user_agent}
@app.get("/itemsTwo/")
async def read_items(*, strange_header: str = Header(None, convert_underscores=False)): ## By default it converts the underscores to hyphen,But now it will not
return {"strange_header": strange_header}
ngrok_tunnel = ngrok.connect(8000)
print('Public URL:', ngrok_tunnel.public_url)
nest_asyncio.apply()
uvicorn.run(app, port=8000)