Skip to content

Commit

Permalink
Merge pull request #3 from AnaPaixao/main
Browse files Browse the repository at this point in the history
delete request created
  • Loading branch information
PauloLeal committed Aug 9, 2023
2 parents dc074a3 + 5850bc2 commit d17aa3b
Showing 1 changed file with 33 additions and 5 deletions.
38 changes: 33 additions & 5 deletions lib/utils/http_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ class HttpUtils {
bool cached = false,
bool hasLog = false,
}) async {
return _reqJson("get", url, headers: headers, cached: cached, hasLog: hasLog);
return _reqJson("get", url,
headers: headers, cached: cached, hasLog: hasLog);
}

static Future<HttpResponse> postJson(
Expand All @@ -43,7 +44,8 @@ class HttpUtils {
bool cached = false,
bool hasLog = false,
}) async {
return _reqJson("post", url, json: json, headers: headers, cached: cached, hasLog: hasLog);
return _reqJson("post", url,
json: json, headers: headers, cached: cached, hasLog: hasLog);
}

static Future<HttpResponse> putJson(
Expand All @@ -53,7 +55,19 @@ class HttpUtils {
bool cached = false,
bool hasLog = false,
}) async {
return _reqJson("put", url, json: json, headers: headers, cached: cached, hasLog: hasLog);
return _reqJson("put", url,
json: json, headers: headers, cached: cached, hasLog: hasLog);
}

static Future<HttpResponse> deleteJson(
String url,
Map<String, dynamic>? json, {
Map<String, String>? headers,
bool cached = false,
bool hasLog = false,
}) async {
return _reqJson("delete", url,
json: json, headers: headers, cached: cached, hasLog: hasLog);
}

static Future<HttpResponse> postFile(
Expand All @@ -62,7 +76,8 @@ class HttpUtils {
String filename, {
Map<String, String>? headers,
}) async {
return _reqJson("upload", url, headers: headers, bytes: bytes, filename: filename);
return _reqJson("upload", url,
headers: headers, bytes: bytes, filename: filename);
}

static String _hashRequest(
Expand Down Expand Up @@ -124,7 +139,8 @@ class HttpUtils {
cachedBody = await ls.getString(cacheKeyBody);
String? status = await ls.getString(cacheKeyStatus);
if (status != null) {
cachedStatus = int.parse(await ls.getString("httpreq-$reqHash-status") ?? "0");
cachedStatus =
int.parse(await ls.getString("httpreq-$reqHash-status") ?? "0");
}
String? etag = await ls.getString(cacheKeyEtag);

Expand All @@ -148,6 +164,18 @@ class HttpUtils {
response = hasLog
? await _httpClient.get(Uri.parse(url), headers: headers)
: await http.get(Uri.parse(url), headers: headers);
} else if (method == "delete") {
response = hasLog
? await _httpClient.delete(
Uri.parse(url),
headers: headers,
body: json != null ? marshalJson(json) : null,
)
: await http.delete(
Uri.parse(url),
headers: headers,
body: json != null ? marshalJson(json) : null,
);
} else {
var f = hasLog ? _httpClient.post : http.post;
if (method == "put") {
Expand Down

0 comments on commit d17aa3b

Please sign in to comment.