C# Application to Firebase – Retrieving the Entire JSON tree

Retrieving the entire JSON tree from a Firebase database through use of a C# application.

In this article we will go through how to retrieve all data from Googles Firebase database using a C# application. To begin with we will look at the namespaces being used within this example of code. The first header we see is System which is present as we are later making use of the console to display any returned data. system.Net is needed as we will be making a web request to our firebase project online. Finally, we also have System.IO which enables us to the stream reader allowing us to read text from a stream of data.

using System;
using System.Net;
using System.IO;

We will now move on to main section of the code which can be found in the snippet below;

var HTTPrequest = (HttpWebRequest)WebRequest.Create("https://myfirebaseproject.firebaseio.com/.json");
var Response = (HttpWebResponse)HTTPrequest.GetResponse();
var StreamReader = new StreamReader(Response.GetResponseStream()).ReadToEnd();
Console.WriteLine(StreamReader);

This could be changed to retrieve data in periodic frequencies depending on what exactly you are wanting to do with it. You can then go on to further manipulate this JSON data depending on your objective. The full source code can be found in the below snippet.

using System;
using System.Net;
using System.IO;

using System.Diagnostics;
namespace WindowsFormsApplication
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
while (true)
{
var HTTPrequest = (HttpWebRequest)WebRequest.Create("https://myfirebaseproject.firebaseio.com/.json");
var Response = (HttpWebResponse)HTTPrequest.GetResponse();
var StreamReader = new StreamReader(Response.GetResponseStream()).ReadToEnd();
Console.WriteLine(StreamReader);
}
}
}
}

Leave a Reply