0

I am making an extremely simple API using flask-restful and want to process POST-parameters without having to require the users to enter a parameter name, e.g.

curl -d "data" localhost

instead of

curl -d "name=data" localhost

The API is used internally so this usage is not problematic, however, I can't get it to work. If I do

parser.add_argument('', type=str)

then I'm still required to use the equality sign, e.g. -d "=data".

parser.add_argumnent(None, type=str)

raises an exception. Without parser.add_argument() parser.parse_args() returns an empty container.

svdc
  • 154
  • 2
  • 10
  • study http://flask.pocoo.org/docs/0.10/api/#flask.Request.args, and make your parsing based in the dict. – brunsgaard Mar 05 '15 at 03:17
  • I dont know how new you are but you can access the request object with `from flask import request` and the used it as `if 'data' in request.args` do something – brunsgaard Mar 05 '15 at 03:18
  • I had to use request.form instead of request.args, but all the same, it works now. Thank you! :) – svdc Mar 05 '15 at 10:39
  • @svd: Do not hesitate to provide the solution you found by writing an answer to your own question. This could be useful to other people ;) – Alexandre Mar 24 '15 at 10:39

1 Answers1

0

As suggested by @brunsgaard:

Request.form captures all the POST (and PUT) data in a dictionary.

If the input is formed exactly as in the question, the following code grabs it from the dictionary:

request.form.keys()[0]
svdc
  • 154
  • 2
  • 10