I've got this boilerplate code:
from flask import Flask, jsonify, request
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
text = request.get_json()
return jsonify({'you sent:': text}), 201
else:
return jsonify({'about': 'hakuna matata'})
@app.route('/multi/<int:num>', methods=['GET'])
def get_multiply10(num):
return jsonify({'result': num*10})
if __name__ == '__main__':
app.run(debug=True)
when I jump into Python interpreter I can interact with the API with GET like this:
from requests import get, post
get('http://localhost:5000').json()
and it returns expected output, but when I try to execute POST request:
post('http://localhost:5000', data={'data': 'bombastic !'}).json()
I get returned None
from the text
variable, meaning POST request is being acknowledged but the data isn't making it through to the variable.
What am I doing wrong ?