getAPI method

Future<BaseResponse> getAPI(
  1. String url,
  2. dynamic data, {
  3. bool hasHeader = true,
  4. int timeout = 20,
  5. bool isFullPath = false,
})

Implementation

Future<BaseResponse> getAPI(String url, data, {bool hasHeader = true, int timeout = 20, bool isFullPath = false}) async {
  final baseResponse = BaseResponse();
  try {
    http.Response response;
    final constants = Constants();
    final uri = Uri.parse(isFullPath ? url : constants.baseUrl + url);
    if (hasHeader && constants.isLogin)
      response = await http.Client().get(uri, headers: await _getHeader()).timeout(Duration(seconds: timeout));
    else
      response = await http.Client().get(uri).timeout(Duration(seconds: timeout));
    if (showLog == true) {
      logDev.log('\n\nadvn-request url: ' + uri.toString());
      logDev.log('\nadvn-response get: ${response.body}');
    }
    baseResponse.fromJson(jsonDecode(response.body), data);
  } catch (e) {
    return _responseError(baseResponse, e);
  }
  return baseResponse;
}