Callable

Type-safe Firebase HTTPS Callable Functions client using Decodable


Keywords
cloudfunctions, cocoapods, decodable, firebase, ios, swift
License
MIT
Install
pod try Callable

Documentation

Callable

License: MIT

Type-safe Firebase HTTPS Callable Functions client using Decodable.

Installation

pod 'Callable'

Usage

Define endpoint and Response

You need to define Response extend Decodable.

  • path
    • The name of the Callable HTTPS trigger.
  • parameter
    • Parameters to pass to the trigger.
struct SampleResponse: Decodable {
    let name: String
}

struct Sample: Callable {
    typealias Response = SampleResponse
    let name: String

    init(name: String) {
        self.name = name
    }

    var path: String {
        return "httpcallable"
    }

    var parameter: [String: Any]? {
        return ["name": name]
    }
}

Call endpoint

If the request succeeds, Response type will be returned.

let sample = Sample(name: "Jobs")
sample.call { result in
    switch result {
    case .success(let resonse):
        print(resonse)
    case .failure(let error):
        print(error)
    }
}
  • CallableError
    • function(Error)
      • server threw an error or if the resulting promise was rejected.
    • decode(Error)
      • decode failed
    • illegalCombination(Any?, Error?)
      • both result and error exist, or nil