Skip to content

Instantly share code, notes, and snippets.

@tarvos21
Forked from johnschimmel/sample_route.py
Created May 26, 2017 17:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tarvos21/6cf0dee3e54bee8b98369255b8969c74 to your computer and use it in GitHub Desktop.
Save tarvos21/6cf0dee3e54bee8b98369255b8969c74 to your computer and use it in GitHub Desktop.
Sample of Flask receiving JSON
# If /json route receives header "application/json"
@app.route("/json", methods=['GET','POST'])
def json():
app.logger.debug("JSON received...")
app.logger.debug(request.json)
if request.json:
mydata = request.json # will be
return "Thanks. Your age is %s" % mydata.get("age")
else:
return "no json received"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment