callApi static method
Implementation
static Future<Map<String, dynamic>> callApi({
required String url,
required String method,
Map<String, dynamic>? body,
}) async {
http.Response response;
final headers = {
"Content-Type": "application/json"
};
switch (method.toUpperCase()) {
case "POST":
response = await http.post(
Uri.parse(url),
headers: headers,
body: jsonEncode(body ?? {}),
);
break;
case "PUT":
response = await http.put(
Uri.parse(url),
headers: headers,
body: jsonEncode(body ?? {}),
);
break;
case "DELETE":
response = await http.delete(
Uri.parse(url), headers: headers);
break;
default:
response = await http.get(
Uri.parse(url), headers: headers);
}
return jsonDecode(response.body);
}