Simple reporting app

In the tutorial we will implement the simplest app without authentication and predefined schema. We will use NodeJS and Express framework, but you can use any other programming language.

Requirements

To create simple app you need to implement only 3 endpoints:

Let's implement them one by one.

Getting app information

App information should have the structure. Let's implement it.

var getSources = function () {
    return [
        {id: 'flowers', name: 'Flowers'},
        {id: 'salaries', name: 'Salaries'},
        {
            id: 'stocks', name: 'Stocks',
            filter: [
                {
                    id: 'price',
                    title: 'Bottom Price',
                    optional: true,
                    type: 'number'
                },
                {
                    id: 'company',
                    title: 'Companies',
                    optional: true,
                    placeholder: 'Select companies',
                    private: true,
                    type: 'multilist',
                    data: [
                        {title: 'Apple', value: 'AAPL'},
                        {title: 'Microsoft', value: 'MSFT'},
                        {title: 'IBM', value: 'IBM'},
                        {title: 'Amazon', value: 'AMZN'}
                    ]
                }
            ]
        }
    ];
};

app.get('/', function (req, res) {
    var app = {
        'name': 'Fibery Samples',
        'version': '2.0',
        'description': 'The set of samples to check Fibery reports in action',
        'authentication': [{
            'id': 'none',
            'name': 'This information is public',
            'description': 'There is no any authentication required. Just press [Connect] button and proceed to charts beauty'
        }],
        'sources': getSources()
    };
    res.json(app);
});

We can see that the app doesn't require any authentication and have 3 sources from schema configuration. Stocks source has some filters to select data more precisely.

You can find more information about the endpoint here.

Validate account

Since authentication is not required, we always return static account name.

app.post('/validate', function (req, res) {
    res.json({name: 'Fibery Samples'});
});

You can find more information about the endpoint here.

Fetching data

The endpoint receives source and filter and should return actual data.

var sendCsvFileAsIs = function (req, res) {
    res.sendFile(resolve('./data/' + req.body.source + '.csv'));
};

var sendFilteredJsonFile = function (req, res) {
    var data = require('./data/' + req.body.source + '.json');
    var companyFilter = req.body.filter['company'] || [];
    var price = req.body.filter['price'] || 0;
    if (!_.isEmpty(companyFilter)) {
        data = _.filter(data, function(row) { return  _.includes(companyFilter, row.company); });
    }

    data = _.filter(data, function (row) {
       return row.price >= price;
    });

    res.json(data);
};

var dataProcessor = {
    'flowers': sendCsvFileAsIs,
    'salaries': sendCsvFileAsIs,
    'stocks': sendFilteredJsonFile
};

app.post('/', function (req, res) {
    dataProcessor[req.body.source](req, res);
});

Let's suppose that our data stores in simple csv and json files. req.body.source contains selected source. For "flowers" and "salaries" sources we don't need to do anything and just return appropriate file content. For stocks source, because of filters, we need to implement logic on filtering data. All filters are sent in request body so we can get it from req.body.filter. We make filtering by price and company and return data array. You can find more information about the endpoint here.

And that's it! Our app is ready to use. See full example here.