post method
Implementation
Future<dynamic> post({
String? baseUrl,
String? authorization,
required String path,
required data,
bool skipJsonDecode = false,
Map<String, String>? headers,
}) async {
http_package.Response? response;
try {
baseUrl ??= Api.getAPIBaseUrls();
final url = Uri.parse(baseUrl + path);
log('POST---$url');
log('POST---DATA---$data');
response = await http_package.post(
url,
body: jsonEncode(data),
headers: headers ?? header(authorization),
);
log('Status Code:${response.statusCode}');
log('Response : ${response.body}');
log('isFailure : ${isFailure(response.statusCode)}');
if (skipJsonDecode || isFailure(response.statusCode)) {
return response.body;
}
if (response.body.isEmpty) {
return <String, dynamic>{};
}
return json.decode(response.body);
} catch (exception) {
log(exception);
return null;
}
}