urlRequest static method

Future<ApiCallResponse> urlRequest(
  1. ApiCallType callType,
  2. String apiUrl,
  3. Map<String, dynamic> headers,
  4. Map<String, dynamic> params,
  5. bool returnBody,
  6. bool decodeUtf8,
)

Implementation

static Future<ApiCallResponse> urlRequest(
  ApiCallType callType,
  String apiUrl,
  Map<String, dynamic> headers,
  Map<String, dynamic> params,
  bool returnBody,
  bool decodeUtf8,
) async {
  if (params.isNotEmpty) {
    final lastUriPart = apiUrl.split('/').last;
    final needsParamSpecifier = !lastUriPart.contains('?');
    apiUrl =
        '$apiUrl${needsParamSpecifier ? '?' : ''}${asQueryParams(params)}';
  }
  final makeRequest = callType == ApiCallType.GET ? http.get : http.delete;
  final response =
      await makeRequest(Uri.parse(apiUrl), headers: toStringMap(headers));
  return ApiCallResponse.fromHttpResponse(response, returnBody, decodeUtf8);
}