Search code examples
pythonjsonpython-3.xflaskflask-restful

How can I create a json structure using all the @api.route paths


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?


Solution

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

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