BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Getting JSON Data with Netflix Falcor

Getting JSON Data with Netflix Falcor

Leia em Português

This item in japanese

Lire ce contenu en français

Bookmarks

Netflix has open sourced Falcor, a JavaScript library offering a model and asynchronous mechanism for fetching JSON data from multiple sources.

Netflix is using Falcor to populate the UI of their web application with JSON data. All the back-end data coming from a memory cache or multiple databases is modeled through a single virtual JSON object. It is called “virtual” because from the client’s perspective the data seems to be in memory, although it can actually reside on local or remote databases.

The data is made available through a JSON graph, using the DataSource interface having the following asynchronous operations: get, set, and call. The client can traverse the graph using JavaScript paths similar to when accessing the JSON data directly. For demonstration purposes, we’ll consider this minimal JSON object:

{
  "greeting": "Hello World"
}

If this object is stored in the file model.json, then accessing it is done as following:

<script src="https://netflix.github.io/falcor/build/falcor.browser.js"></script>
<script>
  var model = new falcor.Model({source: new falcor.HttpDataSource('/model.json') });

  // retrieve the "greeting" key from the root of the Virtual JSON resource
  model.
    get("greeting").
    then(function(response) {
      document.write(response.json.greeting);
    });
</script>

Falcor includes a Router hiding the actual data stores and directing the calls to the appropriate back-end services responsible for retrieving the data. Also, when data is retrieved it is cached to avoid subsequent trips to the database. Falcor can also batch multiple requests, making a single network request, and does not issue duplicate database requests if there is already one in the process.

Netflix has made Falcor available on GitHub, asking the community for help finding and fixing bugs, and integrating it with various MVC frameworks.

Rate this Article

Adoption
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

BT