Commit 4b1f0515 authored by Paul Asmuth's avatar Paul Asmuth
Browse files

honour the format= parameter in {GET,POST} /query

parent b245519d
Loading
Loading
Loading
Loading
+30 −5
Original line number Diff line number Diff line
@@ -224,11 +224,15 @@ void HTTPAPI::executeQuery(
    http::HTTPRequest* request,
    http::HTTPResponse* response,
    util::URI* uri) {
  response->setStatus(http::kStatusOK);
  response->addHeader("Content-Type", "application/json; charset=utf-8");
  auto params = uri->queryParams();

  std::shared_ptr<util::InputStream> input_stream =
      request->getBodyInputStream();
  std::shared_ptr<util::InputStream> input_stream;
  std::string get_query;
  if (util::URI::getParam(params, "q", &get_query)) {
    input_stream.reset(new util::StringInputStream(get_query));
  } else {
    input_stream = request->getBodyInputStream();
  }

  std::shared_ptr<util::OutputStream> output_stream =
      response->getBodyOutputStream();
@@ -237,10 +241,31 @@ void HTTPAPI::executeQuery(
  std::unique_ptr<query::TableRepository> table_repo(
      new MetricTableRepository(metric_repo_));

  query::QueryService::kFormat resp_format = query::QueryService::FORMAT_JSON;
  std::string format_param;
  if (util::URI::getParam(params, "format", &format_param)) {
    if (format_param == "svg") {
      resp_format = query::QueryService::FORMAT_SVG;
    }
  }

  response->setStatus(http::kStatusOK);

  switch (resp_format) {
    case query::QueryService::FORMAT_JSON:
      response->addHeader("Content-Type", "application/json; charset=utf-8");
      break;
    case query::QueryService::FORMAT_SVG:
      response->addHeader("Content-Type", "text/html; charset=utf-8");
      break;
    default:
      break;
  }

  try {
    query_service.executeQuery(
        input_stream,
        query::QueryService::FORMAT_JSON,
        resp_format,
        output_stream,
        std::move(table_repo));

+1 −2
Original line number Diff line number Diff line
@@ -15,14 +15,13 @@

[ frontend ]
    - clean up sql result view
    - metric overview page
    - syntax highlighting
    - embed as iframe
    - hover flyoouts for button bar in sql editor "Refresh, Change View and use CTRL+enter"
    - make editr split draggable/resizable
    - better error message style
    - compare with yesterday in metric preview widget
    - metric preview widget: auto refresh (on/off)
    - make editr split draggable/resizable

[ SQL ]
    - functions: round, median, percentile, delta
+6 −6
Original line number Diff line number Diff line
@@ -133,7 +133,7 @@ Execute a ChartSQL / SQL query and return the result.

<table>
  <tr>
    <th>query <i>(mandatory)</i></th>
    <th>q <i>(mandatory)</i></th>
    <td>
      the ChartSQL / SQL query to execute
    </td>
@@ -141,18 +141,18 @@ Execute a ChartSQL / SQL query and return the result.
  <tr>
    <th>format</th>
    <td>
      the response format: `svg`, `csv`, or `json` (default)
      the response format: `svg` or `json` (default: json)
    </td>
  </tr>
</table>
<br />

#### Examples:

### POST /query

Execute a ChartSQL / SQL query and return the result.
Execute a ChartSQL / SQL query and return the result. Send the ChartSQL query as
the HTTP POST body and use the same GET query parameters as for the
`GET /query` call


#### Parameters:
#### Examples: