Backendbauer

Charts backend

View the Project on GitHub mopinion/Backendbauer

Backendbauer

What it is

Backendbauer is a backend server with REST API for generating json data for frontend js charts. It is written in Go and used by Mopinion.

What it needs

How it works

Only two files are needed to get Backendbauer working:

For testing you can also use server/backendbauer.js

Server.go is the source code. In config.json you can set MySQL databases with custom tables and fields. All settings are based on the url from which the API call is made, the referer.

Install

Go to server folder
$ cd server
build server
$ sudo go build -o server server.go
sudo chmod 755 server
make symbolic link
$ sudo ln -s [backendbauer dir]/server/server /usr/sbin/backendbauer
copy service file to /etc/init.d
$ sudo cp backendbauer /etc/init.d/
sudo chmod 755 /etc/init.d/backendbauer
To start and stop
sudo service backendbauer start
sudo service backendbauer stop
or
nohup [backendbauer dir]/server/server &

MySQL

To test the example execute the sql/my_database.sql file on your local MySQL server. Set the proper username and password in config.json

Try

sudo service backendbauer start
Go to
http://localhost:8888/chart

API

Endpoint:
https://[username]:[password]@[host name]:[port]/data

The API has a number of variables in order to get the right data in json format.

Example request

http://franz:jawohl@localhost:8888/data?x=1&y=1&from_date=2013-04-01&to_date=2013-04-30&avg=1&filter=my_table.rating!12|my_table.rating!11&chart_type=area&series=0&jsonp=false&order=&limit=0&role=0&callback=Backendbauer.place&combined=true

Response

The server responds in json format, with the following fields:

Example response

{
    "categories": [
        "2012-10-01"
        "2012-10-02"
        "2012-10-03"
        "2012-10-04"
        "2012-10-05"
    ],
    "data": [
        ["2012-10-01",6]
        ["2012-10-02",5.3]
        ["2012-10-03",5.8]
        ["2012-10-04",5.6]
        ["2012-10-05",4.8]
    ],
    "x_field_name":"Date",
    "x_labels":true,
    "y_field_name":"Rating over time average"
}

License

Apache 2.0 License (see LICENSE.txt). You can contact me by email floris (at) mopinionlabs.com

Future development