get static method

Future get(
  1. String path, {
  2. Map<String, dynamic> qparams = const {},
  3. Uri? useUri,
  4. String? serviceID,
})

Implementation

static Future get(
  String path, {
  Map<String, dynamic> qparams = const {},
  Uri? useUri,
  String? serviceID,
}) async {
  var client = http.Client();
  try {
    final response = await client.get(
      useUri ?? uri(path, queryparams: qparams, serviceID: serviceID),
      headers: _myHeaders(),
    );
    final decoded = json.decode(response.body);
    if ((response.statusCode / 100).truncate() != 2) {
      throw ApiErrorResponse(decoded["message"]);
    }
    return decoded["data"];
  } catch (e) {
    if (e is SocketException) throw ConnectionRefuted(err: e.message);
    if (e is HttpException) {
      throw ApiErrorResponse("Couldn't find the post 😱");
    }
    if (e is FormatException) throw RespuestaInvalida();
    rethrow;
  } finally {
    client.close();
  }
}