diff options
| author | LV-426 <lv-426@taproot.org.il> | 2014-09-28 18:24:14 +0300 |
|---|---|---|
| committer | LV-426 <lv-426@taproot.org.il> | 2014-09-28 18:24:14 +0300 |
| commit | 3008d35eb298b4ddc0b85a3e0114e4bc0c87fe45 (patch) | |
| tree | 1545a6d8da95c83d8425a4cc8fd5449c30c5c3ef | |
| parent | 267b3d2e4dec5a25afd14634c2c494f302f5c80a (diff) | |
Early Rhizi API prototype:
- load_node_by_id_attr()
- response_wrap()
| -rw-r--r-- | src-py/rhizi_api.py | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src-py/rhizi_api.py b/src-py/rhizi_api.py new file mode 100644 index 00000000..246768aa --- /dev/null +++ b/src-py/rhizi_api.py @@ -0,0 +1,43 @@ +""" +Rhizi web API +""" +import os +import db_controller as dbc +import json +from flask import jsonify + +from flask import Flask +from flask import request + +webapp = Flask(__name__) +webapp.debug = True + +# injected: DB controller +db_ctl = None + +def __response_wrap(data=None, error=None): + """ + wrap response data/errors as dict - this should always be used when returning + data to allow easy return of list objects, assist in error case distinction, etc. + """ + return dict(data=data, error=error) + +@webapp.route("/load/node-single", methods=['POST']) +def load_node_by_id_attr(): + """ + @return: a list containing a single node whose id attribute matches 'id' or + an empty list if the requested node is not found + @raise exception: on error + """ + node_id = request.form['id'] + op = dbc.DBO_load_node_set_by_id_attribute([node_id]) + try: + n = db_ctl.exec_op(op) + ret = __response_wrap(n) + return jsonify(ret) + except Exception as e: + return jsonify('unable to load node with id: {0}'.format(node_id)) + +@webapp.route("/add/node-single") +def add_node(n): + pass |
