GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||
GeezerVison is showing sqlformat.org — API Documentation - sqlformat: Online SQL Formatter API DocumentationThis service provides an API that makes it easy to integrate sqlformat with your own website or your application. The returned data is transferred as JSON objects, except for the response body of error messages which are in plain text. HTTP Status CodesThe API uses the following status codes:
API FunctionsThe service exposes the following endpoints: Format SQL statements
Example request and response body: # POST parameter in request
reindent=1&sql=select+%2A+from+foo
# Response body
{"result": "select *\nfrom foo"}
Split SQL statements
Example request and response body: # POST parameter in request
sql=select+%2A+from+foo%3B+select+%2A+from+bar
# Response body
{"result": ["select * from foo;", "select * from bar"]}
Usage LimitFor now access to the API is limited to 500 requests per hour for a single IP. Please contact me if you hit this limit. ExamplesUsing the API from a Python script: >>> import urllib2, urllib
>>> import json
>>> params = {'sql': 'select * from foo', 'reindent': 1}
>>> response = urllib2.urlopen('https://sqlformat.org/api/v1/format', data=urllib.urlencode(params))
>>> data = json.loads(response.read())
>>> print data['result']
select *
from foo
>>>
Using the API from JavaScript: http://jsfiddle.net/andialbrecht/jq4wd/. Using the API from Bash: #!/bin/bash # # author: Michał Skrzyński ([email protected]) # version: 1.0.2 (28.11.2019) # [ ! -x /usr/bin/curl ] && { echo 'Error: curl is not installed.' >&2 ;exit 1; } [ ! -x /usr/bin/jq ] && { echo 'Error: jq is not installed.' >&2 ;exit 1; } [[ -f "${1}" || -p /dev/stdin ]] && { sql=$(cat "${1:--}"); } || { sql="${1}"; } curl -s -X POST -d "reindent=1&sql=${sql}" https://sqlformat.org/api/v1/format|jq -r .result Thanks to Michał Skrzyński for sharing this script. Using the API from Ruby: require 'uri'
require 'net/http'
require 'json'
uri = URI("https://sqlformat.org/api/v1/format")
https = Net::HTTP.new(uri.host, uri.port)
https.use_ssl = false
body = URI.encode_www_form({:sql => "select * from foo", :reindent => 1, :identifier_case => "upper"})
response = https.post(uri.path, body)
puts JSON.parse(response.body)["result"]
Thanks to Shiva Huang for the Ruby example. Using the API from Powershell # Payload in hashtable
$body = @{
sql = '/* A comment */ seLEecT * from foo where fieldA = 22 and fieldC = "Something" or fieldB=99'
reindent = 1
indent_width = 3
# identifier_case ="upper"
keyword_case = "upper"
strip_comments = 1
}
# Prepare hashtable to be used in the invocation
$params = @{
Uri = 'https://sqlformat.org/api/v1/format'
Method = 'POST'
Body = $body
ContentType = "application/x-www-form-urlencoded"
}
# Invoke using hashtables
$response = Invoke-RestMethod @params
write-host $response.result
# OR
# Invoke using only the payload in the hashtable
$response = Invoke-RestMethod -Uri "https://sqlformat.org/api/v1/format" -method Post -ContentType "application/x-www-form-urlencoded" -Body $body
write-host $response.result
Result then looks like:
SELECT *
FROM foo
WHERE fieldA = 22
AND fieldC = "Something"
OR fieldB=99
Thanks to René Hug for the Powershell example. | ||||||||||||||||||||||||||||
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |