Skip to content

Instantly share code, notes, and snippets.

@lvidarte
Created June 13, 2017 20:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lvidarte/c85bdc3f488b5aee63432bcc9c44488e to your computer and use it in GitHub Desktop.
Save lvidarte/c85bdc3f488b5aee63432bcc9c44488e to your computer and use it in GitHub Desktop.
Generic API
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