delete static method

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

Implementation

static Future delete(
  String path, {
  Object? payload = const {},
  Map<String, dynamic>? qparams,
  Uri? useUri,
  String? serviceID,
}) async {
  var client = http.Client();
  late Uri url;
  try {
    url = useUri ?? uri(path, queryparams: qparams, serviceID: serviceID);
    final response = await client.delete(url, body: jsonEncode(payload), 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, url: url);
    if (e is HttpException) throw ApiErrorResponse("Couldn't find the post 😱");
    if (e is FormatException) throw RespuestaInvalida();
    rethrow;
  } finally {
    client.close();
  }
}