5

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

2
  • 1
    Do you mean /hi?city=NY? Commented Feb 22, 2015 at 20:36
  • @dirn yes GET parameters whatever the url Commented Feb 22, 2015 at 22:08

2 Answers 2

6

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.

Sign up to request clarification or add additional context in comments.

1 Comment

update from flask-restful docs, the request parser has been deprecated, as stated from the website: > The whole request parser part of Flask-RESTful is slated for removal and will be replaced by documentation on how to integrate with other packages that do the input/output stuff better (such as marshmallow).
5

You can use request.args.get('key')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.