getMethodWithToken method
Sends an HTTP GET request to the specified url with an authentication
token and optional API key.
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().getMethodWithToken(url: "https://api.example.com/data", token: "your_token_here");
Implementation
Future<(int statusCode, Map<String, dynamic> data)> getMethodWithToken({
String? url,
var token,
}) async {
try {
var response = await http.get(
Uri.parse(url ?? ""),
headers: (xApiKey ?? "").isNotEmpty
? {
"Content-Type": "application/json",
"Authorization": "Bearer $token",
'x-api-key': (xApiKey ?? ""),
}
: {
"Content-Type": "application/json",
"Authorization": "Bearer $token",
},
);
return _handleResponse(response);
} catch (error, stackTrace) {
throw (error, stackTrace);
}
}