Java Driver for Firebase

I just started a new Project @ GitHub, called jfirebase. That is basically a Java Wrapper for the REST API of Firebase. Clone the git repo and build the package with Maven2 / Maven3 like this:

mvn -Dmaven.test.skip=true package

There are Unit Tests for the project but If you want to run the test cases you have to add your firebase channel to the test classes.

You can install the JAR file with this command into your local Maven Repository:

mvn -Dmaven.test.skip=true install

The Driver contains basically 5 methods to interact with Firebase.

  • boolean write(Map<String, String> map)
  • Reader read(String uri)
  • boolean delete(String uri)
  • void setChannel(String channel)
  • String setKey(String key)

Here is an example for writing data to Firebase.

Map data = new HashMap();
data.put("firstname", "Robert");
data.put("lastname", "Reiz");
IDriver driver = new Driver();
driver.setChannel("http://YOUR_CHANNEL_AT_FIREBASE");
driver.write(data);

Your channel would be something like: “http://demo.firebase.com/myprojectname&#8221;.

OK. Here is an example for reading data.

IDriver driver = new Driver();
driver.setChannel("http://demo.firebase.com/SampleChat/");
Reader reader = driver.read("users/jack");
try{
   ObjectMapper mapper = new ObjectMapper();
   User user = mapper.readValue(reader, User.class);
   System.out.println(user.getName());
} catch (Exception ex){
   ex.printStackTrace();
}

The “read” method returns a “java.io.Reader”. With that you can do what you want. I am using here the jackson-core-lgpl JSON Mapper to map the JSON String from Firebase to my Java class User.

The delete method is pretty straight forward:

IDriver driver = new Driver();
driver.setChannel("http://demo.firebase.com/SampleChat/");
boolean deleted = driver.delete("user/jack");

Let me know if you have questions.

4 thoughts on “Java Driver for Firebase

  1. Thanks for building this. I had a little trouble getting it to work in the beginning but It is smooth sailing now. What else are you planning to do with the firebase project?

    • Hey Ryan. Good question. I didn’t look at the firebase project since round about 6 weeks. Just because I am to busy with the versioneye.com project. And your are the first one who is giving me feedback to this firebase driver.
      If you have any change requests or bugs, than I will continue to work on this project. Your feedback is appreciated.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s