-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
30 lines (21 loc) · 898 Bytes
/
main.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
#pip install fastapi uvicorn
# 1. Library imports
import uvicorn ##ASGI server
from fastapi import FastAPI
# 2. Create the app object
app = FastAPI()
# 3. Index route, opens automatically on http://127.0.0.1:8000
@app.get('/')
def index():
return {'message': 'Hello, World'}
# 4. Route with a single parameter, returns the parameter within a message
# Located at: http://127.0.0.1:8000/AnyNameHere
@app.get('/Welcome')
def get_name(name: str):
return {'Welcome To My Welcome Page Bros': f'{name}'}
# 5. Run the API with uvicorn
# Will run on http://127.0.0.1:8000
if __name__ == '__main__':
uvicorn.run(app, host='127.0.0.1', port=8000)
#To run the execute the file--> uvicorn main:app --reload i.e uvicorn <python_file_name:fastapi_object_name> --reload
#to open swagger UI (allows us to test the API)--> http://127.0.0.1:8000/docs