In Express.js I can configure the whole app to support mimetype json or form with this:
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json());
Then in the routers, I just get the values with:
function (req, res) {
fields =req.body
}
In Flask, I must to use something like this for every route:
if request.mimetype == 'application/json':
res = request.get_json()
else:
res = request.form
firstname = res['firstname']
lastname = res['lastname']
but I don't like using if and else this way. Is there another automatic or cleaner way?