Try Monique.io for free and save 93% of the time needed to set up dashboards and alerts.
The API gives you the possibility to perform calculations based on input data encoded as JSON. The API can be conveniently used from a programming language supporting sending HTTP requests, from a website using the JSONP mechanism, or directly from a command-line interface using curl or similar tools.

API specification

The format of an API URL is:

http://calculator.vhex.net/c/<name>

where <name> is a name of a calculator. Full URLs with <name> filled are displayed at the bottom of a calculator page, which you can access from the main page.

Calculator's arguments must be encoded as a JSON array. Each type of arguments must be encoded as follows:

  • a single number - as a single number
  • a sequence/vector - as an array
  • a matrix - as an array of arrays (rows)

A JSON-encoded array with arguments must be passed directly as POST data or as data GET parameter. The preferred method is to use POST and set Content-Type HTTP header to application/json.

Returned data will be encoded as JSON. In case of an error, a response will have HTTP status code 400 (Bad Request) and will consist of a single string describing the error.

JSONP - using the API from a website

Due to security reasons a website cannot perform an AJAX call to an external server. To overcome the issue, JSONP mechanism can be used.

To use the mechanism, input data must be passed as GET parameter data and the callback GET parameter must contain a name of a Javascript function that will be called with the following three arguments:

  • name of a calculator
  • input data
  • result

The following example shows how to define a callback function resultCallback and how to trigger the computation:

<script>
function resultCallback(calc, args, res) {
    console.log('Got result', res, 'from args', args);
}
</script>

<script src="http://calculator.vhex.net/c/variance?callback=resultCallback&data=[[1,1.2,0.8,1.3]]"></script>

To trigger computations for input data now known statically, you will need to inject <script> elements into HTML tree dynamically.

Examples

Variance of a sequence - command line usage
$ curl calculator.vhex.net/c/variance -d '[[1, 1.2, 0.8, 1.3]]'
0.036875
Passing a matrix - solving linear equations
$ curl calculator.vhex.net/c/linear-equations-solution -d '[ [[1, 2], [3, 4]], [1, 2] ]'
[
  0.0, 
  0.5
]
Generating random samples from the Gaussian distribution
$ curl calculator.vhex.net/c/gaussian -d '[5, 0, 1]' 
[
  1.3923079173126578, 
  0.21834478521029518, 
  0.07133951995455008, 
  -0.7950895862265774, 
  0.29889855429600454
]
Python example using requests library
import requests, json

args = [1,2,3,4,5]
r = requests.post('http://calculator.vhex.net/c/median',
    data=json.dumps([args]),
    headers={'content-type': 'application/json'})
result = r.json()

Using API from Google Apps Script
First we define a generic function for calling any API method:
function callCfx(url, argsArray) {
  var payload = JSON.stringify(argsArray);
  var options = {
     "method" : "post",
     "payload" : payload,
     "contentType": "application/json"
  };
  var result = UrlFetchApp.fetch(url, options);
  return JSON.parse(result.getContentText());
}
Now we can use it by passing API URL as the first argument and arguments as the second:
var res = callCfx('http://calculator.vhex.net/c/hamming-distance', [[1,2,3], [1,4,8]]);

Usage limits

The API is free to use. It accepts input data sizes up to a few megabytes (which equals to hundreds of thousands of numbers). The access can be however throttled or a HTTP response 502 can be returned in case of high system load. Additionally time used by a single API call is limited to a few seconds.