Thursday, January 15, 2015

Writing a Client Using Firebase's Web - JavaScript API

Now that we have built a client to use a RESTful API, we will switch to using Firebase's Web - JavaScript API.

Why? First, Firebases's Web JavaScript API is simple (ok...  so is the client for the RESTful API). Second, most importantly, Firebase's Web JavaScript API is Realtime, i.e., the client is notified of changes in the data.

note: In this particular example, we will not take advantage of the Realtime nature of Web JavaScript API.

In JSFIDDLE, add the following URL to the "External Resources"
<//cdn.firebase.com/js/client/2.0.6/firebase.js>

note: Without the http: or https: the browser will default to the containing page's protocol.

var myDataRef = new Firebase('https://wineapp.firebaseio.com');
var selfRef = myDataRef.child('wineries').once('value', function(snapshot) {
    var wineries = snapshot.val();
    alert(wineries.key1.name);
}, function(error) {
});

No comments:

Post a Comment