Whenever a dataset of the plugin is used in a chart, or is viewed using the data table, a call will be launched to the plugin’s /query endpoint.
Before we proceed, know that there are two types of plugins: pushdown enabled plugins and basic plugins. In this article, we’re implementing the POST /query endpoint for a basic plugin. This means that we will not handle aggregations (sum/avg/etc) in the plugin or in the underlying API/database. For more information on the difference between a pushdown enabled plugin and a basic plugin, please refer to this article.
In a basic plugin, the result of the /query call will return an array of arrays, which follows the exact structure that was defined by the /datasets endpoint. So in other words, if a query is done for a specific dataset, all columns of that dataset should be returned for each row of data.
To be clear on the data structure, we will start with a static example. Note that we return an array of rows, in which we follow the same order of columns as we defined in our /datasets endpoint. Also note that dates must be sent in ISO format: YYYY-MM-DDThh:mm:ssZ. You can use javasript dates in combination with the toISOString() function for this. All dates are interpreted in UTC.
// > index.js
app.post('/query', function(req, res) {
return res.status(200).json([
["Chicken baconito", 6 , "2018-06-06T14:33:34Z"],
["Quesarito", 5.5, "2018-05-18T14:33:34Z"],
...
]);
})