get static method

Future<ResponseAPI> get({
  1. required String methodName,
  2. required String bearerToken,
  3. required String privateKey,
})

Sends a GET request to the given methodName with authentication headers.

  • Uses bearerToken for authorization and privateKey for additional security.
  • Logs the request and response for debugging.
  • Returns a ResponseAPI object containing the response data.

If an error occurs, it is handled and returned as an error response.

Implementation

static Future<ResponseAPI> get({
  required String methodName,
  required String bearerToken,
  required String privateKey,
}) async {
  try {
    ResponseAPI? interNetMap = await _checkConnectivity();
    if (interNetMap != null) {
      return interNetMap; // Return error response if no internet connection.
    }

    String url = ApiConstant.baseUrl + methodName;
    Options options = Options(
      headers: {
        "Content-Type": "application/json",
        "Authorization": "Bearer $bearerToken",
        "key": privateKey,
      },
    );

    logMessage("==request== $url");

    Response response = await _dio.get(url, options: options);

    logMessage("==response== ${response.data}");

    return ResponseAPI(response.statusCode ?? 0, response.data);
  } catch (error) {
    return _handleError(error); // Handle and return error response.
  }
}