{% extends "layout.html" %} {% block title %}reference{% endblock %} {% block head %} {% endblock %} {% block body %}

overview

To allow integration with other web applications and services, statscache offers a simple, easy-to-use REST API with support for multiple convenient data formats.

{# This page really ought to be more thorough #}

queries

The API is accessible under the {{ url_for('plugin_index') }} tree. As this interface is meant to export data, only GET requests are supported on all endpoints.

index

The list of available models is accessible via at {{ url_for('plugin_index') }}. The identifiers are composed of ASCII characters excluding spaces, single or double quotes, punctuation, parantheses, ampersands, and asterisks.

layout

Certain models are associated with a layout attribute that describes the structure of the model. If a given model model has a layout attribute, it is accessible at {{ url_for('plugin_layout', ident='model') }}.

feed

The rows of any model model that was listed by the index may be retrieved at the {{ url_for('plugin_model', ident='model') }} endpoint. Because a literal dump of the database table would be ridicoulously inefficient, the results of any query are paginated using the protocol discussed later. Queries may be customized using the following query string parameters:

formats

With the exception of layouts, all endpoints support serialization to JSON[-P] and CSV. The HTTP Accept header is what determines the format of the response. Both the text/ or application/ prefixes are accepted. Note that a request for JavaScript content is interpreted exactly the same as a request for JSON data, and in either case a JSON-P request will get a response with a JavaScript mime-type.

cross-origin

The statscache web API supports Cross-Origin Resource Sharing (CORS), an opt-in mechanism to allow direct AJAX requests and access to designated response headers. Using CORS requires no additional work on your part, as most major JavaScript libraries transparently activate it when appropriate.

Cross-origin AJAX requests may also be done the traditional way, using JSON-P, but that method is neither necessary not recommended. JSON-P is limited in that there is no way to retrieve the response headers, which statscache uses to pass on important metadata regarding pagination. Still, if you are in a situation where there are compelling reasons to do so, using JSON-P is an option.

pagination

In feed responses, statscache passes on information about pagination through several headers. (If you're familiar with the GitHub API, this mechanism is very similar.) The Link header is used to provide links to the next and previous pages, if they exist. Every response also includes an X-Link-Number and an X-Link-Count header, which give the current page number (starting from one) and the total number of pages, respectively.

{% endblock %}