Reputation: 7743
I need to set my HTSQL server to act as a JSON API server, returning JSON-formatted output by default, not only when a query is followed by /:json
. Is there a way to do this?
Reason: I need to send queries that are formulated by software that automatically places parameters (?foo='bar'&baz='moo'
) at the end of the URL, but HTSQL only recognizes an output format specifier like /:json
when it comes at the absolute end of the URL, after the parameters. I don't know a way to build URLs like that without tedious and error-prone direct manipulation of the entire URL.
In other words, HTSQL demands that URLS look like
/mytable?col1='val1'&col2='val2'/:json
but I can't put the /:json
after the parameters, so I'm looking for a way to have /:json
be automatically implied.
Upvotes: 0
Views: 38
Reputation: 256
The easiest way to do this is to submit the desired format with the Accept
HTTP header. For example, Accept: x-htsql/json
should give you JSON output.
You can also change the default output format, but it's rather tedious: You need to create an HTSQL addon and override htsql.core.fmt.emit.EmitDefault
extension. Perhaps, you can bypass creating an addon by hot-patching this class.
Upvotes: 1