Skip to content

Instantly share code, notes, and snippets.

@Pop101
Last active September 19, 2020 19:42
Show Gist options
  • Save Pop101/f1c2e1893d589c6a87cafd3fb3b3a66c to your computer and use it in GitHub Desktop.
Save Pop101/f1c2e1893d589c6a87cafd3fb3b3a66c to your computer and use it in GitHub Desktop.
A flask starting point for creating a restful api
from functools import wraps
from flask import Flask, request, abort
from waitress import serve
app = Flask(__name__)
APPKEY = 'EXAMPLE_KEY'
def require_appkey(view_function):
@wraps(view_function)
def decorated_function(*args, **kwargs):
if request.args.get('key') and request.args.get('key') == APPKEY:
return view_function(*args, **kwargs)
else:
abort(401)
return decorated_function
@app.route('/', methods=['POST'])
@require_appkey
def post_data():
return request.get_data()
@app.route('/', methods=['GET'])
def get_users():
return 'RESTful api'
serve(app,host='0.0.0.0',port=8080)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment