FirebaseDatabase.Net.Standard.2.1 1.0.2

dotnet add package FirebaseDatabase.Net.Standard.2.1 --version 1.0.2
NuGet\Install-Package FirebaseDatabase.Net.Standard.2.1 -Version 1.0.2
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="FirebaseDatabase.Net.Standard.2.1" Version="1.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add FirebaseDatabase.Net.Standard.2.1 --version 1.0.2
#r "nuget: FirebaseDatabase.Net.Standard.2.1, 1.0.2"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install FirebaseDatabase.Net.Standard.2.1 as a Cake Addin
#addin nuget:?package=FirebaseDatabase.Net.Standard.2.1&version=1.0.2

// Install FirebaseDatabase.Net.Standard.2.1 as a Cake Tool
#tool nuget:?package=FirebaseDatabase.Net.Standard.2.1&version=1.0.2

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.

For Authenticating with Firebase checkout the Firebase Authentication library and related blog post

To upload files to Firebase Storage checkout the Firebase Storage 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 Standard 2.0 - see https://github.com/dotnet/standard/blob/master/docs/versions.md for compatibility matrix

Usage

Authentication

The simplest solution where you only use your app secret is as follows:

var auth = "ABCDE"; // your app secret
var firebaseClient = new FirebaseClient(
  "<URL>",
  new FirebaseOptions
  {
    AuthTokenAsyncFactory = () => Task.FromResult(auth) 
  });

Note that using app secret can only be done for server-side scenarios. Otherwise you should use some sort of third-party login.

var firebaseClient = new FirebaseClient(
  "<URL>",
  new FirebaseOptions
  {
    AuthTokenAsyncFactory = () => LoginAsync()
  });

...

public static async Task<string> LoginAsync()
{
  // manage oauth login to Google / Facebook etc.
  // call FirebaseAuthentication.net library to get the Firebase Token
  // return the token
}
  

As you can se, the AuthTokenAsyncFactory is of type Func<Task<string>>. This is to allow refreshing the expired token in streaming scenarios, in which case the func is called to get a fresh token.

Querying

C#
using Firebase.Database;
using Firebase.Database.Query;

' Since the dinosaur-facts repo no longer works, populate your own one with sample data in "sample.json"
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.");
}
VB.net
Imports Firebase.Database
Imports Firebase.Database.Query

' Since the dinosaur-facts repo no longer works, populate your own one with sample data in "sample.json"
Dim client = New FirebaseClient("https://dinosaur-facts.firebaseio.com/")

Dim dinos = Await client _
    .Child("dinosaurs") _
    .OrderByKey() _
    .StartAt("pterodactyl") _
    .LimitToFirst(2) _
    .OnceAsync(Of Dinosaur)

For Each dino In dinos
    Console.WriteLine($"{dino.Key} is {dino.Object.Height}m high.")
Next

Saving & deleting data

using Firebase.Database;
using Firebase.Database.Query;
...
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)
await firebase
  .Child("dinosaurs")
  .Child("t-rex")
  .PutAsync(new Dinosaur());

// delete given child node
await firebase
  .Child("dinosaurs")
  .Child("t-rex")
  .DeleteAsync();

Realtime streaming

C#
using Firebase.Database;
using Firebase.Database.Query;
using System.Reactive.Linq;
...
var firebase = new FirebaseClient("https://dinosaur-facts.firebaseio.com/");
var observable = firebase
  .Child("dinosaurs")
  .AsObservable<Dinosaur>()
  .Subscribe(d => Console.WriteLine(d.Key));
  
VB.net
Imports System.Reactive.Linq
Imports Firebase.Database
Imports Firebase.Database.Query
' ...
Dim client = New FirebaseClient("https://dinosaur-facts.firebaseio.com/")

child _
  .Child("dinosaurs") _
  .AsObservable(Of InboundMessage) _
  .Subscribe(Sub(f) Console.WriteLine(f.Key))

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

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.2 873 12/15/2019
1.0.0 458 12/12/2019