Skip to content

Rust based library for working with Firebase.

License

Notifications You must be signed in to change notification settings

GT3CH1/rust-firebase

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

95 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rust Firebase

Rust based library for interacting with the Firebase REST API.

Full Documentation

The APIs in this README do not document all of the APIs available! Go to the official docs for the most up to date version of the API.

Load the crate!

Don't forget to include the library in your project:

extern crate firebase;
use firebase::Firebase;

Creating a Firebase reference

Simple

You can currently create a simple reference to your firebase server:

let firebase = Firebase::new("https://<your-firebase>.firebaseio.com");

Authenticated

Or you can create an authenticated connection by supplying your auth token:

let firebase = Firebase::authed("https://<your-firebase>.firebaseio.com", "<token>");

NOTE: You must send your requests through HTTPS or Firebase will reject it. Not specifying HTTPS will also result in an error: ParseError::UrlIsNotHTTPS

Walking the database

Reference nested objects in your server like so:

let show = firebase.at("/shows/futurama"); // points to /shows/futurama
let episode = show.at("s10/meanwhile");    // points to /shows/futurama/s10/meanwhile

Slashes and .json extensions will be handled accordingly:

// All of the following are equivalent:
let show = firebase.at("/shows/futurama.json");
let show = firebase.at("shows/futurama/");
let show = firebase.at("/shows/futurama/");

Working with data

Reading data

Reading data can be done with a simple call to .get()

let response = show.get();

Writing data

let description = episode.at("description");
let response = description.set(serde_json::json!("the last episode"));

Pushing data

let episodes = firebase.at("/shows/futurama/episodes");
let response = episodes.push(serde_json::json!("The Lost Episode!"));

Updating data

let description = episode.at("description");
let response = description.update(serde_json::json!("the penultimate episode"));

Removing data

let episode = firebase.at("/shows/futurama/s10/meanwhile");
let response = episode.remove();

Requests with parameters

let episodes = firebase.at("/shows/futurama/episodes");
let top5 = episodes.order_by("\"imdb\"").limit_to_first(5).get();

The full list of supported parameters are listed here:

  • order_by
  • limit_to_first
  • limit_to_last
  • start_at
  • end_at
  • equal_to
  • shallow

Working with JSON values

  • Json is received and sent as a serde_json Value object.

Example

let json = serde_json::json!({ "name": "David Smith" });

let people = firebase.at("/earth/us/indiana");
let response = people.push(json);

...


#[derive(Serialize,Deserialize)]
struct Person {
    name: String
}
...
let person = Person {
    name: "Gavin"
};

let json = serde_json::to_value(person);
let people = firebase.at("/earth/us/utah");
let response = people.push(json);

Packages

No packages published

Languages

  • Rust 100.0%