1

Below is the code I'm using for Simple REST API. It is working fine. The REST URL is like http://127.0.0.1:8080/sample/100 But I need to pass 100 as a key value pair like http://127.0.0.1:8080/sample?runtime=100. Is this possible or any other python library that will help

app = Flask(__name__)
api = Api(app)

class Analysis(Resource):
def get(self, runtime):
   result2 = result1.to_json(orient='records')
   return json.loads(result2)

api.add_resource(Analysis, '/sample/<runtime>')

if __name__ == '__main__':
   app.run(port='8080')
Krishna
  • 1,089
  • 5
  • 24
  • 38

1 Answers1

0

Check out "The Request Object" section of the Flask Quickstart documentation here: http://flask.pocoo.org/docs/0.12/quickstart/

To access parameters submitted in the URL (?key=value) you can use the args attribute:

searchword = request.args.get('key', '')

make sure you include this in your imports:

from flask import request
andrew g
  • 164
  • 2
  • 8