# Collection of code snippets by Arne Vajhøj 
# (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) 
from flask import Flask, request, Response
import json

msgs = []

app = Flask(__name__)

@app.route('/msgs', methods=['GET'])
def get_all():
    return Response(json.dumps({"message": msgs}), status=200, content_type='application/json')


@app.route('/msgs', methods=['POST'])
def add():
    o = json.loads(request.data)
    msgs.append(o)
    return Response(json.dumps(o), status=200, content_type='application/json')
    
if __name__ == '__main__':
    app.run(host='localhost', port=8001)
