makeApiCall static method

Future<Response> makeApiCall(
  1. String baseUrl,
  2. String apiUrl,
  3. dynamic data,
  4. String apiKey,
)

Implementation

static Future<http.Response> makeApiCall(
    String baseUrl, String apiUrl, dynamic data, String apiKey) async {
  try {
    final actualUrl = Uri.parse('$baseUrl$apiUrl');
    final headers = {'x-api-key': apiKey, 'Content-Type': 'application/json'};

    final response =
        await http.post(actualUrl, headers: headers, body: jsonEncode(data));

    if (response.statusCode >= 200 && response.statusCode < 300) {
      LogService.logger
          .i("Successful API call to Vigil ${response.statusCode}");
      return response;
    } else {
      LogService.logger
          .e("API call failed with status ${response.statusCode}");
      LogService.logger.e("Error response: ${response.body}");
    }
    return response;
  } catch (e) {
    LogService.logger.e("Error while making an API call to vigil: $e");
    rethrow;
  }
}