Skip to content

Type-safe Firebase HTTPS Callable Functions client using Decodable

License

Notifications You must be signed in to change notification settings

starhoshi/Callable

Repository files navigation

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

About

Type-safe Firebase HTTPS Callable Functions client using Decodable

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •