I'm curious how I can take query arguments coming from the GET method in Flask-RESTPlus. I didn't managed to find an example in the documentation.
I have previously used pure flask and the way I was doing it was by calling 'request.args.get()' from the flask library. Any ideas how to achieve this in RESTPlus?
How do you pass arguments in Flask API? Required Arguments To require a value be passed for an argument, just add required=True to the call to add_argument() . parser. add_argument('name', required=True, help="Name cannot be blank!")
Flask-RESTful's request parsing interface, reqparse , is modeled after the argparse interface. It's designed to provide simple and uniform access to any variable on the flask. request object in Flask.
namespace is from the Flask-RESTPlus and Blueprint is from flask to organize your app. the namespaces modules (specific to Flask-RESTPlus) are reusable namespaces designed like you would do with Flask's Blueprint.
Nested Field While nesting fields using dicts can turn a flat data object into a nested response, you can use Nested to unmarshal nested data structures and render them appropriately. This example uses two Nested fields. The Nested constructor takes a dict of fields to render as sub-fields.
It's a Flask plugin, it shouldn't be breaking the Flask interface. So you should be able to get them from flask.request
as always:
import flask
...
print(flask.request.args.get("name"))
I think the most correct solution I found is to use the request parser:
parser = api.parser()
parser.add_argument('user', location='args', help='Queried user')
It is discontinued from RESTPlus. But it is not going any time soon as they have mentioned.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With