Awesome Open Source
Awesome Open Source

FirebaseSwift

Build Status Language GitHub license

FirebaseSwift is intended for server-side Swift and acts as a wrapper around the Firebase REST api. Options for both synchronous and asynchronous calls.

Swift Package Manager

.package(url: "https://github.com/gtchance/FirebaseSwift.git", .upToNextMajor(from: "1.6"))

Example

let firebase = Firebase(
baseURL: "https://myapp.firebaseio.com/",
accessToken: "<MY_GOOGLE_OAUTH2_ACCESS_TOKEN>")
AUTH

See instructions here on creating an access token. You cannot currently create an access token with this library, but you can use an access token you've created elsewhere or use the depricated Database Secret (see below on using a secret instead of an access token)

If you want to use the deprecated Firebase Database Secret, use the auth property:

// Deprecated by Firebase. Use access token in the main example instead.
let firebase = Firebase(baseURL: "https://myapp.firebaseio.com/")
firebase.auth = "<MY_DATABASE_SECRET>"

GET
// sync
let user = firebase.get("user")

// async
firebase.get("user") { user in
  // ...
}
POST
let newUser = [
  "name": "John",
  "email": "[email protected]"
]
// sync
let result = firebase.post(path: "user", value: newUser)
print(result) // ["name": "john_id"]

// async
firebase.post(path: "user", value: newUser) { result in
  // ...
}
PUT
let updatedUser = [
  "name": "John Smith",
  "email": "[email protected]"
]
// can also use setValue(path: ..., value: ...)
// sync
let response = firebase.put(path: "user/john_id", value: updatedUser)

// async
firebase.put(path: "user/john_id", value: updatedUser) { result in
  // ...
}
DELETE
// sync
firebase.delete("user/john_id")

// async
firebase.delete("user/john_id") {
  // ...
}
PATCH
// sync
let result = firebase.patch(path: "user/john_id", value: ["middleInitial": "T"])

// async
firebase.patch(path: "user/john_id", value: ["middleInitial": "T"]) { result in
  // ...
}
I AM NOT AFFILIATED WITH GOOGLE OR FIREBASE IN ANY WAY

If you experience any bugs, please create an issue or submit a pull request.


Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
swift (6,639
firebase (378
backend (159
swift-package-manager (83
server-side-swift (57

Find Open Source By Browsing 7,000 Topics Across 59 Categories