jcoaks / firebase-database-dotnet

C# library for Firebase Realtime Database.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

FirebaseDatabase.net

AppVeyor Build status

Simple wrapper on top of Firebase Realtime Database REST API. Among others it supports streaming API which you can use for realtime notifications.

Authentication with Firebase tokens is also supported, checkout the Firebase Authentication library and related blog post

Installation

// Install release version
Install-Package FirebaseDatabase.net

// Install pre-release version
Install-Package FirebaseDatabase.net -pre

Supported frameworks

  • .NET 4.5+
  • Windows 8.x
  • UWP
  • Windows Phone 8.1
  • CoreCLR

Usage

Querying

var firebase = new FirebaseClient("https://dinosaur-facts.firebaseio.com/");
var dinos = await firebase
  .Child("dinosaurs")
  .OrderByKey()
  .StartAt("pterodactyl")
  .LimitToFirst(2)
  .OnceAsync<Dinosaur>();
  
foreach (var dino in dinos)
{
  Console.WriteLine($"{dino.Key} is {dino.Object.Height}m high.");
}

Saving data

var firebase = new FirebaseClient("https://dinosaur-facts.firebaseio.com/");

// add new item to list of data and let the client generate new key for you (done offline)
var dino = await firebase
  .Child("dinosaurs")
  .PostAsync(new Dinosaur());
  
// note that there is another overload for the PostAsync method which delegates the new key generation to the firebase server
  
Console.WriteLine($"Key for the new dinosaur: {dino.Key}");  

// add new item directly to the specified location (this will overwrite whatever data already exists at that location)
var dino = await firebase
  .Child("dinosaurs")
  .Child("t-rex")
  .PutAsync(new Dinosaur());

Realtime streaming

var firebase = new FirebaseClient("https://dinosaur-facts.firebaseio.com/");
var observable = firebase
  .Child("dinosaurs")
  .AsObservable<Dinosaur>()
  .Subscribe(d => Console.WriteLine(d.Key));
  

AsObservable<T> methods returns an IObservable<T> which you can take advantage of using Reactive Extensions

About

C# library for Firebase Realtime Database.

License:MIT License


Languages

Language:C# 100.0%