delete static method
Implementation
static Future<Response> delete(url,
{Map<String, String>? headers,
Map<String, String>? body,
Encoding? encoding}) async {
try {
Uri newUrl;
if (url.toString().indexOf('https') > -1) {
String hostDir = api.toString().replaceAll('https://', '');
String host = hostDir.indexOf('/') > -1
? hostDir.substring(0, hostDir.indexOf('/'))
: hostDir;
String dir = hostDir.indexOf('/') > -1
? hostDir.replaceAll(host, '').substring(1)
: '';
String request = dir + url.toString().replaceAll(api, '');
newUrl = Uri.https(host, request, body);
} else {
String hostDir = api.toString().replaceAll('http://', '');
String host = hostDir.indexOf('/') > -1
? hostDir.substring(0, hostDir.indexOf('/'))
: hostDir;
String dir = hostDir.indexOf('/') > -1
? hostDir.replaceAll(host, '').substring(1)
: '';
String request = dir + url.toString().replaceAll(api, '');
newUrl = Uri.http(host, request, body);
}
Map<String, String> merger = new Map<String, String>();
merger.addAll({
'Content-Type': 'application/json; charset=UTF-8',
'Accept': 'application/json',
});
if (headers != null) merger.addAll(headers);
final response = await _client.delete(newUrl, headers: merger);
return Response.fromJSON(json.decode(response.body));
} catch (e, trace) {
return Response(
result: false,
status: 500,
message: requestFailedMessage,
reporting: {
'type': 'dart',
'filename': 'repository.dart',
'classname': 'Repository',
'function': 'delete',
'line': 126,
'message': e.toString(),
'trace': trace,
});
}
}