Advertisement
hdiwan

hd1/flaskendpoints

Jun 29th, 2015
636
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.59 KB | None | 0 0
  1. def has_no_empty_params(rule):
  2.     defaults = rule.defaults if rule.defaults is not None else ()
  3.     arguments = rule.arguments if rule.arguments is not None else ()
  4.     return len(defaults) >= len(arguments)
  5.  
  6. def list_endpoints():
  7.     links = []
  8.     for rule in app.url_map.iter_rules():
  9.         # Filter out rules we can't navigate to in a browser
  10.         # and rules that require parameters
  11.         if has_no_empty_params(rule):
  12.             url = flask.url_for(rule.endpoint)
  13.             links.append((url, rule.endpoint))
  14.     return flask.make_response(flask.jsonify({'links': links}), 200)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement