FirebaseFunctions Framework Reference Stay organized with collections Save and categorize content based on your preferences.
Callable
publicstructCallable<Request,Response>:SendablewhereRequest:Encodable,Response:DecodableACallable is a reference to a particular Callable HTTPS trigger in Cloud Functions.
Note
If the Callable HTTPS trigger accepts no parameters,Never can be used foriOS 17.0+. Otherwise, a simple encodable placeholder type (e.g.,struct EmptyRequest: Encodable {}) can be used.The timeout to use when calling the function. Defaults to 70 seconds.
Declaration
Swift
publicvartimeoutInterval:TimeInterval{getset}Executes this Callable HTTPS trigger asynchronously.
The data passed into the trigger must be of the generic
Requesttype:The request to the Cloud Functions backend made by this method automatically includes aFCM token to identify the app instance. If a user is logged in with FirebaseAuth, an auth ID token for the user is also automatically included.
Firebase Cloud Messaging sends data to the Firebase backend periodically to collectinformationregarding the app instance. To stop this, see
Messaging.deleteData(). Itresumes with a new FCM Token the next time you call this method.Declaration
Swift
publicfunccall(_data:Request,completion:@escaping@MainActor(Result<Response,Error>)->Void)Parameters
dataParameters to pass to the trigger.
completionThe 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:
letgreeter=functions.httpsCallable("greeter",requestType:GreetingRequest.self,responseType:GreetingResponse.self)greeter(data){resultinprint(result.greeting)}You can also call a HTTPS Callable function using the following syntax:
letgreeter:Callable<GreetingRequest,GreetingResponse>=functions.httpsCallable("greeter")greeter(data){resultinprint(result.greeting)}Declaration
Swift
publicfunccallAsFunction(_data:Request,completion:@escaping@MainActor(Result<Response,Error>)->Void)Parameters
dataParameters to pass to the trigger.
completionThe 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
Requesttype:The request to the Cloud Functions backend made by this method automatically includes aFCM token to identify the app instance. If a user is logged in with FirebaseAuth, an auth ID token for the user is also automatically included.
Firebase Cloud Messaging sends data to the Firebase backend periodically to collectinformationregarding the app instance. To stop this, see
Messaging.deleteData(). Itresumes 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(iOS13,tvOS13,macOS10.15,watchOS7,*)publicfunccall(_data:Request)asyncthrows->ResponseParameters
dataThe
Requestrepresenting the data to pass to the trigger.Return Value
The decoded
ResponsevalueCreates a directly callable function.
This allows users to call a HTTPS Callable Function like a normal Swift function:
letgreeter=functions.httpsCallable("greeter",requestType:GreetingRequest.self,responseType:GreetingResponse.self)letresult=tryawaitgreeter(data)print(result.greeting)You can also call a HTTPS Callable function using the following syntax:
letgreeter:Callable<GreetingRequest,GreetingResponse>=functions.httpsCallable("greeter")letresult=tryawaitgreeter(data)print(result.greeting)Declaration
Swift
@available(iOS13,tvOS13,macOS10.15,watchOS7,*)publicfunccallAsFunction(_data:Request)asyncthrows->ResponseParameters
dataParameters to pass to the trigger.
Return Value
The decoded
Responsevalue
Creates a stream that yields responses from the streaming callable function.
The request to the Cloud Functions backend made by this method automatically includes a FCMtoken to identify the app instance. If a user is logged in with Firebase Auth, an auth IDtoken for the user is included. If App Check is integrated, an app check token is included.
Firebase Cloud Messaging sends data to the Firebase backend periodically to collectinformation regarding the app instance. To stop this, see
Messaging.deleteData(). Itresumes with a new FCM Token the next time you call this method.Important
The final result returned by the callable function is only accessible whenusingStreamResponseas theResponsegeneric type.Example of using
streamwithoutStreamResponse:letcallable:Callable<MyRequest,MyResponse>=// ...letrequest:MyRequest=// ...letstream=trycallable.stream(request)fortryawaitresponseinstream{// Process each `MyResponse` messageprint(response)}Example of using
streamwithStreamResponse:letcallable:Callable<MyRequest,StreamResponse<MyMessage,MyResult>>=// ...letrequest:MyRequest=// ...letstream=trycallable.stream(request)fortryawaitresponseinstream{switchresponse{case.message(letmessage):// Process each `MyMessage`print(message)case.result(letresult):// Process the final `MyResult`print(result)}}Throws
AFunctionsErrorif the parameterdatacannot be encoded.Declaration
Swift
funcstream(_data:Request?=nil)throws->AsyncThrowingStream<Response,Error>Parameters
dataThe
Requestdata to pass to the callable function.Return Value
A stream wrapping responses yielded by the streaming callable function ora
FunctionsErrorif an error occurred.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-07-15 UTC.