i'm wondering how to fetch GET
parameters in flask-restful like his
/hi/city?=NY
i can do like this /hi/city/NY
using /hi/city/<string:ccc>
but how to do so with /hi/city?=NY
.
i checked the documentation and it seems like using reqparse
: http://flask-restful.readthedocs.org/en/latest/reqparse.html but still couldn't figure out how
You can use the RequestParser
bundled along with Flask-Restful.
from flask_restful import reqparse
class YourAPI(restful.Resource):
def get(self):
parser = reqparse.RequestParser()
parser.add_argument('city')
args = parser.parse_args()
city_value = args.get('city')
By default, the request parser searches json, form fields and query string (as it is in your case) for the key named city
. The variable city_value
will have the value passed in the API request.
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