requestWithBody static method
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,
)
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);
}