Skip to content

Instantly share code, notes, and snippets.

@betterdatascience
Created October 28, 2020 06:31
Show Gist options
  • Save betterdatascience/77410e0a4b20a50c8e5fcd9299320bdd to your computer and use it in GitHub Desktop.
Save betterdatascience/77410e0a4b20a50c8e5fcd9299320bdd to your computer and use it in GitHub Desktop.
001_fastapi
# 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