3

I'm working on my first POST method route in my API. For some reason when I pass variables to it via url http://test.com/test?stuff=wee, Flask throws errors like stuff didn't make it through.

Code:

@app.route('/test', methods = ['POST'])
def testindex():

    stuff = request.args.get('stuff')

    response_message = "success"
    response_data = stuff
    errors = "None"
    response = {
        'response message' : response_message,
        'response data': response_data,
        'errors' : errors
    }

    js = json.dumps(response)
    resp = Response(js, status=200, mimetype='application/json')
    return resp

cURL:

curl -H "Content-Type: application/json" -X POST -d '{"stuff":"wee"}' http://test.com/test?stuff=wee

response:

{"errors": "None", "response data": null, "response message": "success"}

Help?

Josh Usre
  • 674
  • 1
  • 12
  • 35

1 Answers1

3

request.args.get is for getting parameters from GET. You'll want request.form.

Celeo
  • 5,583
  • 8
  • 39
  • 41