Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

flask-restful how to fetch GET parameter

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

like image 285
Hamoudaq Avatar asked Dec 20 '22 06:12

Hamoudaq


1 Answers

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.

like image 67
Phalgun Avatar answered Dec 28 '22 07:12

Phalgun