Skip to content

Instantly share code, notes, and snippets.

@jeffbrl
Created October 3, 2015 22:42
Show Gist options
  • Save jeffbrl/7b6fd9fea55a8594a51d to your computer and use it in GitHub Desktop.
Save jeffbrl/7b6fd9fea55a8594a51d to your computer and use it in GitHub Desktop.
Simple JSON API example in Python
# test with
# curl -X POST -H "Content-Type: application/json" -d '{ "action" : "RUN"}'
# http://127.0.0.1:5000/example/
import json
from flask import request, url_for
from flask.ext.api import FlaskAPI, status, exceptions
app = FlaskAPI(__name__)
def do_action(action):
return "OK"
@app.route('/example/', methods=['POST'])
def example():
result_status = 'UNKNOWN'
if request.method == 'POST':
keys = request.data.keys()
for key, value in request.data.iteritems():
if(key == 'action'):
result_status = do_action(value)
return {'result_status': result_status }
if __name__ == "__main__":
app.run(debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment