applyRequestService method

Future<Map<String, dynamic>> applyRequestService({
  1. required String path,
  2. required Object data,
  3. Map<String, String>? headers,
})

Implementation

Future<Map<String, dynamic>> applyRequestService({
  required String path,
  required Object data,
  Map<String, String>? headers,
}) async {
  final url = Uri.parse('${config.baseUrl}$path');
  final response = await _client.post(
    url,
    headers: {
      ..._gatewayHeaders,
      if (headers != null) ...headers,
    },
    body: data is String ? data : jsonEncode(data),
  );

  if (response.statusCode < 200 || response.statusCode >= 300) {
    throw DataleonApiException(
      'Failed to apply request service for $path',
      statusCode: response.statusCode,
    );
  }

  if (response.body.isEmpty) {
    return const <String, dynamic>{};
  }

  return jsonDecode(response.body) as Map<String, dynamic>;
}