Skip to content

cristinadeac/firebase-client-scala

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Codacy Badge Build status Maven Central

This is a Scala REST client for Firebase, which is based on Circe and is intended for services that don't require realtimeness of Firebase and just need to ger read/write access to the database in a convenient way.

Features:

  • Fetching access token based on admin credentials aka service accounts;
  • CRUD operations;
  • Listing / adding / removing users [TBD].

Documentation

Authentication

One thing to always remember: in order to use this lib, you need a service account, and your app will always be accessing data on behalf of that service account. Kind of "admin access", so it's responsibility of your app to make sure that all the changes are legitimate.

Example

Database operations:

import java.nio.file.{Files, Paths}
import io.github.mkotsur.firebase.auth.AdminCredentials
import io.github.mkotsur.firebase.rest.FirebaseClient
import io.circe.generic.auto._
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits._

val jsonKey: Array[Byte] = Files.readAllBytes(
    Paths.get(getClass.getResource("/rest-client-scala-test-b1940c24c184.json").toURI)
)

val client = new FirebaseClient("rest-client-scala-test")
implicit val token = FirebaseClient.getToken(AdminCredentials(jsonKey)).get

// Reading a primitive
val ageFuture: Future[Option[Int]] = client.get[Int]("users/001/age")

// Reading an object as a case class
case class User(age: Int)
val userFuture: Future[Option[User]] = client.get[User]("users/001")


// more examples in ./src/test/scala/io/github/mkotsur/firebase/rest/FirebaseClientTest.scala

Caveats

  • The library adds BouncyCastle provider at runtime. Not necessarily a bad thing, but something to be aware of;
  • There is a transitive dependency on Guava via gitkitclient;
  • Behavior of FirebaseUsers.createUser mimics gitkit behavior may be somewhat counter-intuitive. Please make sure to fully understand how it works before using in your app.

Adding to your project

libraryDependencies += "io.github.mkotsur" %% "firebase-client-scala" % {latest-version}

Development

The tests are executed against a firebase instance rest-client-scala-test (configured in application-test.conf).

There should be a user: mike@example.com / 123qwe.

About

Scala REST client for Firebase.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Scala 100.0%