requestWithBody static method

Future<ApiCallResponse> requestWithBody(
  1. ApiCallType type,
  2. String apiUrl,
  3. Map<String, dynamic> headers,
  4. Map<String, dynamic> params,
  5. String? body,
  6. BodyType? bodyType,
  7. bool returnBody,
  8. bool encodeBodyUtf8,
  9. bool decodeUtf8,
)

Implementation

static Future<ApiCallResponse> requestWithBody(
  ApiCallType type,
  String apiUrl,
  Map<String, dynamic> headers,
  Map<String, dynamic> params,
  String? body,
  BodyType? bodyType,
  bool returnBody,
  bool encodeBodyUtf8,
  bool decodeUtf8,
) async {
  assert(
    {ApiCallType.POST, ApiCallType.PUT, ApiCallType.PATCH}.contains(type),
    'Invalid ApiCallType $type for request with body',
  );
  final postBody =
      createBody(headers, params, body, bodyType, encodeBodyUtf8);

  if (bodyType == BodyType.MULTIPART) {
    return multipartRequest(
        type, apiUrl, headers, params, returnBody, decodeUtf8);
  }

  final requestFn = {
    ApiCallType.POST: http.post,
    ApiCallType.PUT: http.put,
    ApiCallType.PATCH: http.patch,
  }[type]!;
  final response = await requestFn(Uri.parse(apiUrl),
      headers: toStringMap(headers), body: postBody);
  return ApiCallResponse.fromHttpResponse(response, returnBody, decodeUtf8);
}