call method

  1. @override
Future<Response> call(
  1. HttpMethod method, {
  2. String path = '',
  3. Map<String, String> headers = const {},
  4. Map<String, dynamic> params = const {},
  5. ResponseType? responseType,
})

Send the API request.

Implementation

@override
Future<Response> call(
  HttpMethod method, {
  String path = '',
  Map<String, String> headers = const {},
  Map<String, dynamic> params = const {},
  ResponseType? responseType,
}) async {
  await init();

  // Combine headers to check for dev key
  final combinedHeaders = {..._headers!, ...headers};

  // Only include credentials when dev key is not set
  if (combinedHeaders['X-Appwrite-Dev-Key'] == null) {
    _httpClient.withCredentials = true;
  } else {
    _httpClient.withCredentials = false;
  }

  late http.Response res;
  http.BaseRequest request = prepareRequest(
    method,
    uri: Uri.parse(_endPoint + path),
    headers: combinedHeaders,
    params: params,
  );
  try {
    final streamedResponse = await _httpClient.send(request);
    res = await toResponse(streamedResponse);

    final cookieFallback = res.headers['x-fallback-cookies'];
    if (cookieFallback != null) {
      debugPrint(
        'Appwrite is using localStorage for session management. Increase your security by adding a custom domain as your API endpoint.',
      );
      addHeader('X-Fallback-Cookies', cookieFallback);
      web.window.localStorage['cookieFallback'] = cookieFallback;
    }
    return prepareResponse(res, responseType: responseType);
  } catch (e) {
    if (e is AppwriteException) {
      rethrow;
    }
    throw AppwriteException(e.toString());
  }
}