Created
June 13, 2017 20:22
-
-
Save lvidarte/c85bdc3f488b5aee63432bcc9c44488e to your computer and use it in GitHub Desktop.
Generic API
This file contains hidden or 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 flask import Flask, request, jsonify | |
app = Flask(__name__) | |
data = {} | |
@app.route("/<name>", methods=['GET', 'POST']) | |
def endpoint(name): | |
if request.method == 'POST': | |
if name not in data: | |
data[name] = [] | |
data[name].append(request.get_json(force=True)) | |
return jsonify({'result': 'ok'}) | |
else: | |
return jsonify(data[name] if name in data else []) | |
if __name__ == '__main__': | |
app.run(port=8080) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment