getMethod method

Future<(int, Map<String, dynamic>)> getMethod({
  1. String? url,
  2. Map<String, String>? headers,
})

Sends an HTTP GET request to the specified url with optional headers.

Returns a Future that completes with a (int, Map<String, dynamic>) containing the status code and the response data.

Throws an exception if the request fails.

Example usage:

var response = await ApiMethods().getMethod(url: "https://api.example.com/data");

Implementation

Future<(int statusCode, Map<String, dynamic> data)> getMethod({
  String? url,
  Map<String, String>? headers,
}) async {
  try {
    var response = await http.get(
      Uri.parse(url ?? ""),
      headers: headers,
    );
    return _handleResponse(response);
  } catch (error, stackTrace) {
    throw (error, stackTrace);
  }
}