query static method

Future<String?> query(
  1. Uri url, {
  2. Client? client,
})

Sends a GET request to url with optional client and returns the response body or null if any exception happens.

Implementation

static Future<String?> query(Uri url, {http.Client? client}) async {
  client = client ?? http.Client();

  try {
    final response = await client.get(url);
    if (response.statusCode != 200) {
      throw Exception(
        'Expected status code 200 but got ${response.statusCode} - ${response.body}',
      );
    }

    return response.body;
  } catch (exception) {
    return null;
  }
}