getResponse method

Future<String> getResponse(
  1. String endpoint, {
  2. int? page,
  3. int? limit,
})

Executes a GET request at the given API endpoint with optional pagination parameters.

Implementation

Future<String> getResponse(String endpoint, {int? page, int? limit}) async {
  final params = <String, dynamic>{};
  if (page != null) {
    params['page'] = '$page';
  }
  if (limit != null) {
    params['limit'] = '$limit';
  }
  final uri = unsafe
      ? Uri.http(apiBaseUrl, '$apiBasePath$endpoint', params)
      : Uri.https(apiBaseUrl, '$apiBasePath$endpoint', params);
  final response = await _client.get(uri);

  if (response.statusCode != httpOkay) {
    throw http.ClientException(
      'Got unexpected status code ${response.statusCode}',
      uri,
    );
  }
  return response.statusCode != httpOkay ? '' : response.body;
}