Initial Checkin of REST API support
[plcapi.git] / PLC / RestAPI.py
1 from flask import Flask, url_for, request, Response, jsonify
2 app = Flask(__name__)
3
4 from PLC.API import PLCAPI
5 from PLC.Config import Config
6 from PLC.Logger import logger
7
8 api = PLCAPI()
9
10 get_response = """
11 <html><head>
12 <title>PLCAPI Nova JSON REST Interface</title>
13 </head><body>
14 <h1>PLCAPI Nova JSON REST Interface</h1>
15 <p>Please use HTTP to access the PLCAPI. </p>
16 </body></html>
17 """
18
19 @app.route('/')
20 def api_root():
21     return 'Welcome'
22
23 @app.route('/auth', methods=['GET', 'POST'])
24 def AuthCheck():
25     if request.method == 'POST':
26         args = [request.json.get('auth')]
27         return api.call(None, 'AuthCheck', *args)
28     return get_response
29       
30 @app.route('/roles', methods=['GET', 'POST'])
31 def GetRoles():
32     if request.method == 'POST':
33         logger.error(request.data) 
34         return jsonify(**request.json)
35     return get_response 
36