BT

Getting JSON Data with Netflix Falcor

| by Abel Avram Follow 11 Followers on Aug 19, 2015. Estimated reading time: 1 minute |

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 Stage
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.

Tell us what you think

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

Email me replies to any of my messages in this thread
Community comments

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

Email me replies to any of my messages in this thread

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

Email me replies to any of my messages in this thread

Discuss

Login to InfoQ to interact with what matters most to you.


Recover your password...

Follow

Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.

Like

More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.

Notifications

Stay up-to-date

Set up your notifications and don't miss out on content that matters to you

BT