Last active
September 19, 2020 19:42
-
-
Save Pop101/f1c2e1893d589c6a87cafd3fb3b3a66c to your computer and use it in GitHub Desktop.
A flask starting point for creating a restful api
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
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