“In addition to giving developers near real-time access to our data, we got out of the box well designed, easy to use SDKs for iOS, Android and the Web, in addition to a REST API for developers building server apps. It should hopefully making switching your apps fairly painless.”
var ref = new Firebase("https://hacker-news.firebaseio.com/v0/"); var itemRef; ref.child('topstories').child(0).on('value', function(snapshot) { if(itemRef) { itemRef.off(); } //Get the ID of the top article var id = snapshot.val(); //Get the article details and update in realtime itemRef = ref.child('item').child(id); itemRef.on('value', function(snapshot) { var item = snapshot.val(); document.getElementById("score").innerHTML = item.score; var anchor = document.getElementById("article_a") anchor.innerHTML = item.title; anchor.href = item.url; document.getElementById("comments_a").href = "https://news.ycombinator.com/item?id=" + item.id; }); });
Firebase *ref = [[Firebase alloc] initWithUrl:@"https://hacker-news.firebaseio.com/v0/"]; __block Firebase *itemRef = nil; Firebase *topStories = [ref childByAppendingPath:@"topstories"]; Firebase *firstStory = [topStories childByAppendingPath:@"0"]; FirebaseHandle handle = [firstStory observeEventType:FEventTypeValue withBlock:^(FDataSnapshot *snapshot) { if(itemRef != nil) { [itemRef removeObserverWithHandle: handle]; } NSString *itemId = [NSString stringWithFormat:@"item/%@",snapshot.value]; itemRef = [ref childByAppendingPath:itemId]; [itemRef observeEventType:FEventTypeValue withBlock:^(FDataSnapshot *itemSnap) { NSLog(@"%@", itemSnap.value); }]; }];
final Firebase ref = new Firebase("https://hacker-news.firebaseio.com/v0/"); final Map<Long, ValueEventListener> valueEventListenerMap = new HashMap(); ref.child("topstories").child("0").addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot snapshot) { if(!valueEventListenerMap.isEmpty()) { for(Long id : valueEventListenerMap.keySet()) { ref.child("item").child(String.valueOf(id)).removeEventListener(valueEventListenerMap.get(id)); } valueEventListenerMap.clear(); } //Get the ID of the top article Long id = (Long) snapshot.getValue(); //Get the article details and update in realtime ValueEventListener articleListener = ref.child("item").child(String.valueOf(id)).addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot snapshot) { Map itemMap = (Map) snapshot.getValue(); // Print the title to the console System.out.println(itemMap.get("title")); } @Override public void onCancelled(FirebaseError firebaseError) { } }); valueEventListenerMap.put(id, articleListener); } @Override public void onCancelled(FirebaseError firebaseError) { } });
Check out the full HN documentation at hacker-news.firebaseapp.com.
With more than 100,000 developers using our platform, we’ve seen Firebase used both as the entire backend for apps as well as to power specific realtime features in apps. A growing use case has been loading data into Firebase to expose an API to other developers. Traditionally, building and maintaining a public API is a big undertaking; often entire teams are dedicated to it. It’s not easy to give third party developers access to your data in a way that’s both safe for your users and powerful for those developers. With Firebase, all you need to do is sync data to your Firebase and API consumers can then use one of Firebase’s realtime clients or the REST API to consume that data. You don’t have to worry about scaling with developer usage and or documenting anything beyond your data structure. You can learn more in a blog post we published last year.
We can’t wait to see what you build!