invoke static method

Future invoke(
  1. String methodName,
  2. dynamic body, {
  3. InvokeOptions? options,
})

Implementation

static Future invoke(String methodName, body,
    {InvokeOptions? options}) async {
  final encodedBody = _encodeBody(body);
  final url = Uri.parse(_getApplicationUrl() + "/$methodName");
  final headers = prefs.headers;

  if (options != null) {
    if (options.executionType != null)
      headers['bl-execution-type'] = describeEnum(options.executionType!);
    if (options.httpRequestHeaders != null)
      headers.addAll(options.httpRequestHeaders!);
  }

  var userToken = await BackendlessUserService._instance.getUserToken();

  if (userToken != null) headers['user-token'] = userToken;

  return http
      .post(
    url,
    headers: headers,
    body: encodedBody,
  )
      .then((response) {
    if (response.statusCode >= 400) {
      try {
        throw new BackendlessException.fromJson(jsonDecode(response.body));
      } on FormatException {
        throw new BackendlessException(response.body);
      }
    }
    return jsonDecode(utf8.decode(response.bodyBytes));
  });
}