GET should be idempotent and append things to a querystring POST is for data to be processed
SIMPLE GET ROUTES
Default methods is just get
@app.route('/users/<userid>', methods = ['GET'])defapi_users(userid): users ={'1':'john','2':'steve','3':'bill'}if userid in users:returnjsonify({userid:users[userid]})else:returnnot_found()
SIMPLE POST REQUESTS
Query String
request.args.get('uid')
Data sent
from flask import json@app.route('/messages', methods = ['POST'])defapi_message():ifnot request.is_json:returnjsonify({"msg": "Missing JSON in request"}),400 token = request.json.get('token', None)
Combo
@app.route('/login', methods=['POST', 'GET'])deflogin(): error =Noneif request.method =='POST':ifvalid_login(request.form['username'], request.form['password']):returnlog_the_user_in(request.form['username'])else: error ='Invalid username/password'# the code below is executed if the request method# was GET or the credentials were invalidreturnrender_template('login.html', error=error)