Created
October 28, 2020 06:31
-
-
Save betterdatascience/77410e0a4b20a50c8e5fcd9299320bdd to your computer and use it in GitHub Desktop.
001_fastapi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 1. Library imports | |
import uvicorn | |
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, stranger'} | |
# 4. Route with a single parameter, returns the parameter within a message | |
# Located at: http://127.0.0.1:8000/AnyNameHere | |
@app.get('/{name}') | |
def get_name(name: str): | |
return {'message': f'Hello, {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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment