Skip to content

Instantly share code, notes, and snippets.

@curtisforrester
Created March 24, 2020 12:21
Show Gist options
  • Save curtisforrester/9b74597ae3f02db460ea9c51f2def995 to your computer and use it in GitHub Desktop.
Save curtisforrester/9b74597ae3f02db460ea9c51f2def995 to your computer and use it in GitHub Desktop.
A route to list routes
@bp.route('/routes', methods=['GET'])
def get_routes():
"""
A route to show registered routes.
:return:
"""
rules = []
for rule in current_app.url_map.iter_rules():
methods = ','.join(sorted(rule.methods))
rules.append((rule.endpoint, methods, str(rule)))
ret_data = []
sort_by_rule = operator.itemgetter(2)
for endpoint, methods, rule in sorted(rules, key=sort_by_rule):
route = '{:50s} {:25s} {}'.format(endpoint, methods, rule)
ret_data.append(route)
text = '{}\n'.format('\n'.join(ret_data))
return text
@curtisforrester
Copy link
Author

To view the routes with "curl" (my routes will differ from yours) :)
curl 0/routes

aa.cluster_info                                    GET,HEAD,OPTIONS          /apiv2/aa/cluster_info
aa.get_dnsmasq_conf                                GET,HEAD,OPTIONS          /apiv2/aa/dnsmasq-conf
aa.gen_dnsmasq                                     GET,HEAD,OPTIONS          /apiv2/aa/gen-dnsmasq
aa.gen_host_vars                                   GET,HEAD,OPTIONS          /apiv2/aa/gen-host_vars
aa.host_vars                                       GET,HEAD,OPTIONS          /apiv2/aa/host_vars/<hostname>
aa.get_hosts_content                               GET,HEAD,OPTIONS          /apiv2/aa/hosts-content
aa.dyn_inventory                                   GET,HEAD,OPTIONS          /apiv2/aa/inventory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment