-
-
Save dirkakrid/4fe29a79850e7ff3894d42ff8f99f653 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