get method

Future get(
  1. String endpoint
)

Implementation

Future<dynamic> get(String endpoint) async {
  Map<String, String> headers = {
  "Content-Type": "application/json",
  };

  // Add the Authorization header only if apiKey is not null
  if (apiKey != null) {
    headers["Authorization"] = "Bearer $apiKey";
  }

  final response = await http.get(
    Uri.parse('$baseUrl/$endpoint'),
    headers: headers,
  );

  if (response.statusCode == 200) {
    return json.decode(response.body);
  } else {
    // Better error handling
    // You could throw a custom exception here or handle the error based on the status code
    throw Exception('Failed to post data: Status code ${response.statusCode}, ${response.reasonPhrase}');
  }
}