Created
October 3, 2015 22:42
-
-
Save jeffbrl/7b6fd9fea55a8594a51d to your computer and use it in GitHub Desktop.
Simple JSON API example in Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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