call method

Future<Response> call(
  1. String name, {
  2. dynamic data,
  3. String? idToken,
  4. Map<String, String>? extraHeaders,
})

Invokes an onCall or onCallWithData function by name.

Constructs the standard callable wire format ({"data": ...}) and the optional Authorization: Bearer <idToken> header automatically.

Returns the raw Shelf Response; use parseCallableResponse to extract the result payload.

Implementation

Future<Response> call(
  String name, {
  dynamic data,
  String? idToken,
  Map<String, String>? extraHeaders,
}) {
  final headers = <String, String>{
    'content-type': 'application/json',
    if (idToken != null) 'authorization': 'Bearer $idToken',
    ...?extraHeaders,
  };
  final request = Request(
    'POST',
    Uri.parse('http://localhost/${toCloudRunId(name)}'),
    body: jsonEncode({'data': data}),
    headers: headers,
  );
  return _invoke(toCloudRunId(name), request);
}