File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11from 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 ('/' )
77def page ():
8- return {"message" : "Main page... " }
8+ return {"message" : "Hello, World! " }
99
10- @app .get ('/api/greet' )
10+ @api .get ('/api/greet/ ' )
1111def 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)
You can’t perform that action at this time.
0 commit comments