diff --git a/app.py b/app.py index 59247dc..5c6e80a 100644 --- a/app.py +++ b/app.py @@ -534,6 +534,49 @@ def plot_query(query_id): plot_div = generate_plot(results_df, title) return plot_div +def get_routes(): + + return routes + +@app.route('/endpoints') +def list_endpoints(): + """ + Lists all API endpoints available in the Flask application. + + This endpoint retrieves all registered routes, excluding static routes, + and displays their details such as endpoint name, URL, allowed HTTP methods, + view function name, and a brief description. + """ + routes = [] + for rule in app.url_map.iter_rules(): + if rule.endpoint == 'static': + continue + methods = ', '.join(sorted(rule.methods - {'HEAD', 'OPTIONS'})) + route_info = { + 'endpoint': rule.endpoint, + 'url': rule.rule, + 'methods': methods, + 'view_func': app.view_functions[rule.endpoint].__name__, + 'doc': app.view_functions[rule.endpoint].__doc__ + } + routes.append(route_info) + + search = request.args.get('search', '').lower() + if search: + routes = [ + route for route in routes + if search in route['endpoint'].lower() + or search in route['url'].lower() + or search in route['methods'].lower() + or search in route['view_func'].lower() + or (route['doc'] and search in route['doc'].lower()) + ] + + if htmx: + return render_template('partials/endpoints_table.html', routes=routes) + + return render_template('endpoints.html', routes=routes) + @app.teardown_appcontext def closeConnection(exception): db.close_connection() diff --git a/templates/base.html b/templates/base.html index 8535f55..2e9e4b4 100644 --- a/templates/base.html +++ b/templates/base.html @@ -108,26 +108,11 @@ -
{{ routes|length }} Routes Available
+| Endpoint | +URL | +Methods | +View Function + | +Description + | +
|---|---|---|---|---|
| {{ route.endpoint }} | +{{ route.url }} | +{{ route.methods }} | +{{ route.view_func }} | +
+ {% if route.doc %}
+
+
+ {% else %}
+ N/A
+ {% endif %}
+ + {{ route.doc.split('\n')[0] }}{% if route.doc.count('\n') > 0 %}...{% endif %} ++
+ {{ route.doc }}
+
+ |
+