Requests/Routing
GET should be idempotent and append things to a querystring POST is for data to be processed
Code
Contains
request.args
the key/value pairs in the URL query string
request.form
the key/value pairs in the body, from a HTML post form, or JavaScript request that isn't JSON encoded
request.values
combined args and form, preferring args if keys overlap
request.files
files in the body, which Flask keeps separate from form. HTML forms must use enctype=multipart/form-data or files will not be uploaded.
request.data
mimetype Flask does not handle as string
request.get_json()
Get JSON body from a post request
SIMPLE GET ROUTES
Default methods is just get
@app.route('/users/<userid>', methods = ['GET'])
def api_users(userid):
users = {'1':'john', '2':'steve', '3':'bill'}
if userid in users:
return jsonify({userid:users[userid]})
else:
return not_found()SIMPLE POST REQUESTS
Query String
Data sent
Combo
Last updated