{"id":15294858,"url":"https://github.com/firebase4s/firebase4s","last_synced_at":"2025-05-07T03:46:15.319Z","repository":{"id":27695918,"uuid":"112663014","full_name":"firebase4s/firebase4s","owner":"firebase4s","description":"A Firebase SDK for Scala","archived":false,"fork":false,"pushed_at":"2022-01-02T19:11:32.000Z","size":245,"stargazers_count":23,"open_issues_count":2,"forks_count":7,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-05-07T03:46:04.832Z","etag":null,"topics":["database","firebase","firebase-sdk","realtime-database","scala"],"latest_commit_sha":null,"homepage":"","language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/firebase4s.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-11-30T21:35:36.000Z","updated_at":"2022-01-23T06:47:54.000Z","dependencies_parsed_at":"2022-08-07T13:00:59.220Z","dependency_job_id":null,"html_url":"https://github.com/firebase4s/firebase4s","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firebase4s%2Ffirebase4s","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firebase4s%2Ffirebase4s/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firebase4s%2Ffirebase4s/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firebase4s%2Ffirebase4s/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/firebase4s","download_url":"https://codeload.github.com/firebase4s/firebase4s/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252810274,"owners_count":21807759,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","firebase","firebase-sdk","realtime-database","scala"],"created_at":"2024-09-30T17:07:39.425Z","updated_at":"2025-05-07T03:46:15.299Z","avatar_url":"https://github.com/firebase4s.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cimg src=\"logo/logo-side-text.png?raw=true\" width=400px /\u003e\n\n[![Build Status](https://travis-ci.org/firebase4s/firebase4s.svg?branch=master)](https://travis-ci.org/firebase4s/firebase4s)\n[![Latest version](https://index.scala-lang.org/firebase4s/firebase4s/firebase4s/latest.svg?color=orange\u0026v=1)](https://index.scala-lang.org/firebase4s/firebase4s/firebase4s)\n[![Gitter chat](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/firebase4s/firebase4s)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n### Overview\n\nFirebase4s aims to provide a Scala-friendly alternative to the [Firebase Java SDK](https://github.com/firebase/firebase-admin-java).  By providing more idiomatic API interfaces and automatically handling Scala-to-Java data conversions, Firebase4s eliminates much of the [boilerplate](https://medium.com/@RICEaaron/scala-firebase-da433df93bd2) required to use the Java SDK.  Firebase4s currently provides the same [Realtime Database](#database) and [Authentication](#authentication) features as the Java SDK and aims to provide all of the same [functionality](https://firebase.google.com/docs/admin/setup) over time.\n\n\n----------\n\u003ca name=\"getting-started\"\u003e\u003c/a\u003e\n### Getting Started\n\nTo use `firebase4s` in your project, add the following to your `build.sbt`:\n\n```scala\nlibraryDependencies += \"com.github.firebase4s\" %% \"firebase4s\" % \"0.0.4\"\n```\n\n\n\n----------\n\u003ca name=\"initialize\"\u003e\u003c/a\u003e\n### Initialize\n\nInitialize the `App` with your Firebase service account credentials and database url, which may be obtained from the [Firebase console](https://console.firebase.google.com).\n\n```scala\nimport com.firebase4s.App\n\nval serviceAccount = getClass.getResourceAsStream(\"/serviceAccountCredentials.json\")\n\nApp.initialize(serviceAccount, \"https://\u003cMY_INSTANCE\u003e.firebaseio.com\")\n```\n*The above code snippet assumes that your Firebase service account credentials exist in your project's `resources` directory.*\n\n\n\u003ca name=\"database\"\u003e\u003c/a\u003e\n### Realtime Database\n\nTo get an instance of a `DatabaseReference`:\n```scala\nimport com.firebase4s.database.Database\n\nval db: Database = Database.getInstance()\nval fooRef: DatabaseReference = db.ref(\"foo\")\n```\nThere are five *categories* of supported data types:\n\n##### \u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;*Simple Types*:  `String`, `Boolean`, `Int`, `Long`, `Double`\n##### \u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;*Maps containing Simple Types*: `Map[String, String]`, `Map[String, Boolean]`, etc.\n##### \u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;*Iterables containing Simple Types*: `List[String]` , `Vector[Long]`, etc.\n##### \u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;*Options of any of the above*: `Option[Int]`, `Option[List[String]]`, etc.\n##### \u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;*Classes*\n\n*Currently, only [`JavaBean`](https://en.wikipedia.org/wiki/JavaBeans) classes are supported.  However, Firebase4s offers a [`toMap`](#toMap) helper method which makes working with non-nested case classes easier.  Future versions of Firebase4s will fully support the use of `case classes` through the use of [Scala Macro Annotations](https://docs.scala-lang.org/overviews/macros/annotations.html). and/or [Shapeless](https://github.com/milessabin/shapeless)*\n\n#### Examples:\n\nSet and retrieve a `List[Int]`:\n```scala\n/** Get a database reference */\nval listRef: DatabaseReference = db.ref(\"myList\")\n\n/** Set value at reference location */\nval result: Future[List[Int]] = liftRef.set(List(1, 2, 3))\n\n/** Get value at ref location */\nref.get()\n  .map(snapshot =\u003e snapshot.getValue)\n  .map((list: Option[List[Int]]) =\u003e ???) // handle result\n\n\n```\n\nSet and retrieve a `User`:\n\n```scala\nimport scala.beans.BeanProperty\n\n/** JavaBean Class Constructor */\nclass User() {\n  @BeanProperty var name: String = _\n  @BeanProperty var email: String = _\n}\n\n/** Get a database reference */\nval userRef = db.ref(\"user\")\n\n/** Create user */\nval user = new User()\nuser.name = \"timothy\"\nuser.email = \"tim@example.com\"\n\n/** Set user at ref location */\nuserRef.set(user).foreach(println) // User(\"timothy\",\"tim@example.com\")\n\n/** Get user at ref location */\nuserRef.get()\n  .map(snapshot =\u003e snapshot.getValue(classOf[User]))\n  .map((user: Option[UserRecord]) =\u003e ???) // handle result\n\n```\n\u003ca name=\"toMap\"\u003e\u003c/a\u003e\nWorking with  `case classes`:\n\n```scala\n/**\n  * The Helpers module provides a `toMap` method which\n  * we can invoke on our case class to convert it to a\n  * Map[String, Any] that can be set as a value in the\n  * in the database.  When retrieving the value as this\n  * ref location, we will get back a Map[String, Any]\n  * representation of our case class instance.\n  */\n\nimport com.firebase4s.database.Helpers._\n\ncase class User(name: String, age: Int)\n\nval user = User(\"tim\", 44)\nval userRef = db.ref(\"user\")\n\nuserRef.set(user.toMap)\n\nuserRef.get().foreach(snapshot =\u003e {\n  println(snapshot.getValue) // Map(name -\u003e tim, age -\u003e 44)\n})\n\n```\n\n\n\u003ca name=\"auth\"\u003e\u003c/a\u003e\n### Authentication\n\n##### Create a User:\n```scala\nimport com.firebase4s.{Auth, UserCreationProps}\n\nval auth: Auth = Auth.getInstance()\n\n// User Props\nval props = UserCreationProps(\n  email = Some(\"tim@firebase4s.com\"),\n  displayName = Some(\"tim\"),\n  phoneNumber = Some(\"+1555555555\"),\n  photoUrl = Some(\"http://testing.com/photo.jpeg\")\n)\n\nauth.createUser(props)\n  .map((user: UserRecord) =\u003e ???) // handle results\n\n```\n\n##### Update a User:\n```scala\nimport com.firebase4s.{Auth, UserUpdateProps}\n\nval auth: Auth = Auth.getInstance()\n\n// Props to update\nval props = UserUpdateProps(\n  email = Some(\"timothy@firebase4s.com\"),\n  phoneNumber = Some(\"+15655655555\")\n)\n\nauth.updateUser(props)\n  .map((user: UserRecord) =\u003e ???) // handle results\n\n```\n##### Delete a User:\n\n```scala\nauth.deleteUser(user.uid)\n  .map(uid =\u003e ???) // handle result\n\n```\n\n##### Verify a Firebase ID Token:\n\n```scala\nauth.verifyIdToken(token)\n  .map((token: FirebaseToken) =\u003e token.uid)\n  .map(userId =\u003e ???)\n```\n##### Create a Custom Token:\n```scala\nval extraClaims = Map(\"admin\" -\u003e true)\nauth.createCustomToken(uid, Some(extraClaims)))\n  .map(token =\u003e ???]) // Provide token to client\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffirebase4s%2Ffirebase4s","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffirebase4s%2Ffirebase4s","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffirebase4s%2Ffirebase4s/lists"}