From 311291ae58fd6baae47fff7b1efd8c47c102c25c Mon Sep 17 00:00:00 2001 From: Andi Albrecht Date: Thu, 15 Dec 2011 08:56:57 +0100 Subject: Update API documentation and simplify usage of reindent option. --- extras/appengine/sqlformat/legacy.py | 5 +++++ extras/appengine/sqlformat/templates/api.html | 20 ++++++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) (limited to 'extras/appengine/sqlformat') diff --git a/extras/appengine/sqlformat/legacy.py b/extras/appengine/sqlformat/legacy.py index b563a38..7f6c161 100644 --- a/extras/appengine/sqlformat/legacy.py +++ b/extras/appengine/sqlformat/legacy.py @@ -73,6 +73,7 @@ def api(): @legacy.route('/format/', methods=['GET', 'POST']) +@legacy.route('/format', methods=['GET', 'POST']) def format_(): if request.method == 'POST': sql = _get_sql(request.form, request.files) @@ -140,6 +141,10 @@ def _format_sql(sql, data, format='html'): popts['reindent'] = True except (ValueError, TypeError): pass + if (not 'indent_width' in popts and + data.get('reindent', '').lower() in ('1', 'true', 't')): + popts['indent_width'] = 2 + popts['reindent'] = True if data.get('output_format', None) is not None: popts['output_format'] = data.get('output_format') logging.debug('Format: %s, POPTS: %r', format, popts) diff --git a/extras/appengine/sqlformat/templates/api.html b/extras/appengine/sqlformat/templates/api.html index 79bf118..ebfd83a 100644 --- a/extras/appengine/sqlformat/templates/api.html +++ b/extras/appengine/sqlformat/templates/api.html @@ -7,7 +7,7 @@

Using the API for this application is pretty simple. Just send a - POST request to + request to

http://sqlformat.appspot.com/format/ @@ -15,9 +15,10 @@

Options

- The POST request accepts various options to control - formatting. Only the data option is required. All others - are optional. + The server accepts various options to control formatting. Only + the data option is required. All others are optional.
+ Either use GET and pack the options in the query string + or POST and submit your parameters as form data.

@@ -49,4 +50,15 @@ Download sqlformat_example_client.py

+

+ And another example using curl and a GET request: +

+
+$ curl "http://localhost:8080/format?keyword_case=upper&reindent=true&data=select%20*%20from%20foo;"
+SELECT *
+FROM foo;
+$
+
+ + {% endblock %} -- cgit v1.2.1