# HG changeset patch # User Kim Alvefur # Date 1579979460 -3600 # Node ID 45b04f05d624ca366281373b3fe0f4925669ad97 # Parent 3b6b8dcff78e6833d3a8ea8d53dbbb6fa3966fd8 mod_rest: Add some comments to example code diff -r 3b6b8dcff78e -r 45b04f05d624 mod_rest/example/app.py --- a/mod_rest/example/app.py Sat Jan 25 20:06:48 2020 +0100 +++ b/mod_rest/example/app.py Sat Jan 25 20:11:00 2020 +0100 @@ -5,11 +5,20 @@ @app.route("/api", methods=["OPTIONS"]) def options(): + """ + Startup check. Return an appropriate Accept header to confirm the + data type to use. + """ + return Response(status=200, headers={"accept": "application/json"}) @app.route("/api", methods=["POST"]) def hello(): + """ + Example RESTful JSON format stanza handler. + """ + print(request.data) if request.is_json: data = request.get_json() @@ -18,13 +27,16 @@ return Response(status=400) if data["kind"] == "message" and "body" in data: + # Reply to a message return jsonify({"body": "Yes this is flask app"}) elif data["kind"] == "iq" and data["type"] == "get": if "ping" in data: + # Respond to ping return Response(status=204) elif "disco" in data: + # Return supported features return jsonify( { "disco": { @@ -45,11 +57,13 @@ ) elif "items" in data: + # Disco items return jsonify( {"items": [{"jid": "example.org", "name": "Example Dot Org"}]} ) elif "version" in data: + # Version info return jsonify({"version": {"name": "app.py", "version": "0"}}) return Response(status=501)