diff --git a/examples/client.py b/examples/client.py index a821140..4008fe0 100644 --- a/examples/client.py +++ b/examples/client.py @@ -2,7 +2,14 @@ import requests import abp, json s = requests.Session() -output = json.loads(s.get("http://localhost:5000/state").content) -print output -state = json.loads(s.post("http://localhost:5000/state").content) +output = s.get("http://localhost:5000/state").content +s.post("http://localhost:5000/state", output).content + +s.get("http://localhost:5000/add/99") +s.get("http://localhost:5000/add/100") + +print s.get("http://localhost:5000/state").content + +s.get("http://localhost:5000/clear") +s.close() diff --git a/server/server.py b/server/server.py index 4564a57..7ca3680 100644 --- a/server/server.py +++ b/server/server.py @@ -1,4 +1,5 @@ from flask import Flask, request, render_template, jsonify +import json import abp graphstate = abp.GraphState() @@ -8,18 +9,39 @@ app = Flask(__name__) def index(): return render_template("index.html") -@app.route("/state") +@app.route("/state", methods = ["GET", "POST"]) def state(): if request.method == "GET": return jsonify(graphstate.to_json()) elif request.method == "POST": - graphstate.from_json(request.data) + graphstate.from_json(json.loads(request.data)) return jsonify(graphstate.to_json()) -@app.route("/state") -def state(): +@app.route("/add/") +def add(node): + """ Add a node to the graph """ + graphstate.add_node(node) + return jsonify(graphstate.to_json()) + +@app.route("/rotate//") +def rotate(node): + """ Add a node to the graph """ + graphstate.act_local_rotation(node, operation) return jsonify(graphstate.to_json()) +@app.route("/cz//") +def cz(a, b): + """ Add a node to the graph """ + graphstate.act_cz(a, b) + return jsonify(graphstate.to_json()) + +@app.route("/clear") +def clear(): + """ Clear the current state """ + graphstate = abp.GraphState() + return jsonify({"clear": "ok"}) + + if __name__ == "__main__": app.debug = True app.run(host="0.0.0.0")