FirebaseFunctions Framework Reference

Callable

public struct Callable<Request, Response> where Request : Encodable, Response : Decodable

A Callable is reference to a particular Callable HTTPS trigger in Cloud Functions.

  • The timeout to use when calling the function. Defaults to 60 seconds.

    Declaration

    Swift

    public var timeoutInterval: TimeInterval { get set }
  • Executes this Callable HTTPS trigger asynchronously.

    The data passed into the trigger must be of the generic Request type:

    The request to the Cloud Functions backend made by this method automatically includes a FCM token to identify the app instance. If a user is logged in with Firebase Auth, an auth ID token for the user is also automatically included.

    Firebase Cloud Messaging sends data to the Firebase backend periodically to collect information regarding the app instance. To stop this, see Messaging.deleteData(). It resumes with a new FCM Token the next time you call this method.

    Declaration

    Swift

    public func call(_ data: Request,
                     completion: @escaping (Result<Response, Error>)
                       -> Void)

    Parameters

    data

    Parameters to pass to the trigger.

    completion

    The block to call when the HTTPS request has completed.

  • Creates a directly callable function.

    This allows users to call a HTTPS Callable Function like a normal Swift function:

        let greeter = functions.httpsCallable("greeter",
                                              requestType: GreetingRequest.self,
                                              responseType: GreetingResponse.self)
        greeter(data) { result in
          print(result.greeting)
        }
    

    You can also call a HTTPS Callable function using the following syntax:

        let greeter: Callable<GreetingRequest, GreetingResponse> =
    functions.httpsCallable("greeter")
        greeter(data) { result in
          print(result.greeting)
        }
    

    Declaration

    Swift

    public func callAsFunction(_ data: Request,
                               completion: @escaping (Result<Response, Error>)
                                 -> Void)

    Parameters

    data

    Parameters to pass to the trigger.

    completion

    The block to call when the HTTPS request has completed.

  • Executes this Callable HTTPS trigger asynchronously.

    The data passed into the trigger must be of the generic Request type:

    The request to the Cloud Functions backend made by this method automatically includes a FCM token to identify the app instance. If a user is logged in with Firebase Auth, an auth ID token for the user is also automatically included.

    Firebase Cloud Messaging sends data to the Firebase backend periodically to collect information regarding the app instance. To stop this, see Messaging.deleteData(). It resumes with a new FCM Token the next time you call this method.

    Throws

    An error if any value throws an error during encoding or decoding.

    Throws

    An error if the callable fails to complete

    Declaration

    Swift

    @available(iOS 13, tvOS 13, macOS 10.15, watchOS 7, *)
    public func call(_ data: Request) async throws -> Response

    Parameters

    data

    The Request representing the data to pass to the trigger.

    Return Value

    The decoded Response value

  • Creates a directly callable function.

    This allows users to call a HTTPS Callable Function like a normal Swift function:

        let greeter = functions.httpsCallable("greeter",
                                              requestType: GreetingRequest.self,
                                              responseType: GreetingResponse.self)
        let result = try await greeter(data)
        print(result.greeting)
    

    You can also call a HTTPS Callable function using the following syntax:

        let greeter: Callable<GreetingRequest, GreetingResponse> =
    functions.httpsCallable("greeter")
        let result = try await greeter(data)
        print(result.greeting)
    

    Declaration

    Swift

    @available(iOS 13, tvOS 13, macOS 10.15, watchOS 7, *)
    public func callAsFunction(_ data: Request) async throws -> Response

    Parameters

    data

    Parameters to pass to the trigger.

    Return Value

    The decoded Response value