-1

I have a file called apis.py which has many API's implemented using @api.route notation.eg:

    @api.route('/read', methods=['GET'])
    @api.route('/write', methods=['POST'])

How can get all these @api.routes paths stored somewhere? may be a hashmap / json which holds the url and the purpose of the url for eg: {"read":"/read"}. Mya be using a python script which reads all these annotations?

codec
  • 7,978
  • 26
  • 71
  • 127

1 Answers1

-1

Just in case if you are using Flask, you can try this snippet:

http://flask.pocoo.org/snippets/117/

Stanley Kirdey
  • 602
  • 5
  • 20
  • Thanks a lot! I will try this. I have registered my flask application using app.register_blueprint(simple_page, url_prefix='/pages') . How can I read this url_prefix in my python code? may be store it in a variable? or some way to make this as a global variable so that I can read it anywhere in my python code? – codec Apr 08 '16 at 06:42
  • You can try this iteration: for rule in app.url_map.iter_rules(): – Stanley Kirdey Apr 08 '16 at 16:38