3.9 KiB
layout, title, recline-deps
| layout | title | recline-deps |
|---|---|---|
| container | Library - Example - Loading data from different sources using Backends | true |
Loading data from different sources using Backends
These set of examples will show you how you can load data from different sources such as Google Docs or the DataHub using Recline.
Note: often you are loading data from a given source in order to display it using the various Recline views. However, you can also happily use this data with your own code and app and this is a very common use-case.
Moreover, Recline is designed so you need only include the backend and its dependencies without needing to include any of the dependencies for the view portion of the Recline library.
Overview
Backends connect Dataset and Documents to data from a specific 'Backend' data source. They provide methods for loading and saving Datasets and individuals Documents as well as for bulk loading via a query API and doing bulk transforms on the backend.
You can use a backend directly e.g.
{% highlight javascript %} var backend = recline.Backend.ElasticSearch.fetch({url: ...}); {% endhighlight %}
But more usually the backend will be created or loaded for you by Recline and all you need is provide the identifier for that Backend e.g.
{% highlight javascript %} var dataset = recline.Model.Dataset({ backend: 'backend-identifier' }); {% endhighlight %}
Included Backends
- elasticsearch: ElasticSearch Backend
- dataproxy: DataProxy Backend (CSV and XLS on the Web)
- gdocs: Google Docs (Spreadsheet) Backend
- csv: Local CSV file backend
Backend not on this list that you would like to see? It's very easy to write a new backend -- see below for more details.
Preparing your app
This is as per the quickstart but the set of files is much more limited if you are just using a Backend. Specifically:
{% highlight html %}
{% endhighlight %}
Loading Data from Google Docs
We will be using the following Google Doc. For Recline to be able to access a Google Spreadsheet it must have been 'Published to the Web' (enabled via File -> Publish to the Web menu).
{% highlight javascript %} {% include example-backends-gdocs.js %} {% endhighlight %}
Result
Writing your own backend
Writing your own backend is easy to do. Details of the required API are in the Backend documentation.