Skip to content
Ishmael-Moreno edited this page Aug 5, 2018 · 5 revisions

Installation (NuGet)

Install-Package FireSharp -Version 1.1.0

Usage

FirebaseClient uses RestSharp JsonSerializer by default but there are other options such as ServiceStack.Text and Json.Net Set FirebaseConfig Serializer property for register custom serializer.

Enable Json.Net Serializer (optional)

Install-Package FireSharp.Serialization.JsonNet

Enable ServiceStack.Text Serializer (optional)

Install-Package FireSharp.Serialization.ServiceStack

How can I configure FireSharp?


There is a simple configuration section in web.config file.

<firebase>
     <connectionFactory basePath="**your firebase path**" authSecret="**your firebase auth secret**" />
</firebase>
  • basePath - Required - your firebase path
  • authSecret - Optional - your firebase auth secret
IFirebaseConfig config = new FirebaseConfig ();
                                              
config.Serializer=new ServiceStackJsonSerializer(); //Register ServiceStack.Text
config.Serializer=new JsonNetSerializer();          //Register Json.Net

IFirebaseClient  client = new FirebaseClient(config);

So far, supported methods are :

client.Set(path, data)
client.Get(path)
client.Push(path, data)
client.Delete(path)
client.Update(path,data)
    
client.SetTaskAsync(path, data)
client.GetTaskAsync(path)
client.PushTaskAsync(path, data)
client.DeleteTaskAsync(path)
client.UpdateTaskAsync(path,data)

Listen Streaming from the REST API (Takes 3 arguments)

EventStreamResponse response = await client.OnAsync("chat", (s, args,context) => {
System.Console.WriteLine(args.Data);
});

//Call dispose to stop listening for events
response.Dispose();

Set

var todo = new Todo {
                name = "Execute SET",
                priority = 2
            };
SetResponse response = _client.Set("todos/set", todo);
Todo result = response.ResultAs<Todo>(); //The response will contain the data written

Push

 var todo = new Todo {
                name = "Execute PUSH",
                priority = 2
            };
PushResponse response = _client.Push("todos/push", todo);
response.Result.Name //The result will contain the child name of the new data that was added

Get

 FirebaseResponse response = _client.Get("todos/set");
 Todo todo=response.ResultAs<Todo>(); //The response will contain the data being retreived

Update

var todo = new Todo {
                name = "Execute UPDATE!",
                priority = 1
            };

FirebaseResponse response = _client.Update("todos/set", todo);
Todo todo = response.ResultAs<Todo>(); //The response will contain the data written

Delete

DeleteResponse response = _client.Delete("todos"); //Deletes todos collection
response.Success; //Delete success flag

PushTaskAsync

var todo = new Todo {
                name = "Do your homework!",
                priority = 1
            };

PushResponse response = await _client.PushTaskAsync("todos", todo);
response.Result.Name //The result will contain the child name of the new data that was added