apiGet method

Future apiGet({
  1. required String endpoint,
  2. Map<String, dynamic>? queryParameters,
  3. required BuildContext context,
})

GET method for REST API call

Pass UserModel as user required for authentication based on app token

Pass String as endpoint

Implementation

Future<dynamic> apiGet({
  required String endpoint,
  Map<String, dynamic>? queryParameters,
  required BuildContext context,
}) async {
  try {
    // String? token = await FirebaseAuth.instance.currentUser!.getIdToken();
    _dio.options.headers["x-api-key"] = _apiKey;
    _dio.options.headers["x-user-id"] = _userId;

    // log("API GET CALL : ${apiBaseUrl + endpoint}");

    dio.Response rawResponse = await _dio.get(apiBaseUrl + endpoint,
        queryParameters: queryParameters,
        options: dio.Options(
          followRedirects: false,
          validateStatus: (status) {
            return status! < 300;
          },
        ));

    return rawResponse.data;
  } on dio.DioException catch (e) {
    log(e.response.toString());
    rethrow;
  }
}