Skip to content

Commit 29f5158

Browse files
committed
Minor FastAPI update.
1 parent 005b98e commit 29f5158

1 file changed

Lines changed: 19 additions & 8 deletions

File tree

FastAPI/src/main.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
11
from fastapi import FastAPI
2-
import uvicorn
2+
import requests as r
33

4-
app = FastAPI()
4+
api = FastAPI()
55

6-
@app.get('/')
6+
@api.get('/')
77
def page():
8-
return {"message": "Main page..."}
8+
return {"message": "Hello, World!"}
99

10-
@app.get('/api/greet')
10+
@api.get('/api/greet/')
1111
def greet():
12-
return {"message": "Hello there!"}
12+
return {"message": "Hello!"}
1313

14-
if __name__ == "__main__":
15-
uvicorn.run(app, host="127.0.0.1", port=8000)
14+
@api.get('/api/greet/{name}')
15+
def greet_person(name: str):
16+
return {"message": f"Hello there {name}!"}
17+
18+
@api.get('/api/weather/{location}')
19+
def weather(location: str):
20+
url = f"https://wttr.in/{location}"
21+
response = r.get(url = url)
22+
return response.text
23+
24+
25+
#if __name__ == "__main__":
26+
# uvicorn.run(app, host="127.0.0.1", port=8000)

0 commit comments

Comments
 (0)