python:flask-api
Table of Contents
Output result from API
The BASH below is not specific to Flask, but the MySQL probably is.
Debugging API calls
Send to this URL to see just what you have actually sent to help any debugging.
Send to POST test data
curl -i -X POST \ -H 'Content-Type: application/json' \ -d "{\"auth_token\":\"${AUTH_TOKEN}\", \"user_id\":\"${EMAIL}\", \"file_ref\":\"File.odt\", \"uuid\":\"${UUID}\"}" \ http://192.168.11.7:5000/api
Output
Get output from MySQL in the form of a Tuple and return it without any html encoding, ie. just as a json object. It has a 200 hard coded, but it might be wise to check that the result from MySQL is sensible and justifies a 200 return.
mycursor = mydb.cursor() mycursor.execute(sql) user_id = mycursor.fetchone() # returns a tuple lookup_userid = {"userid":user_id[0]} response = make_response(jsonify({"id": str(lookup_userid) }), 200,) response.headers["Content-Type"] = "application/json" return response
python/flask-api.txt · Last modified: by andrew