send method
Implementation
Future<JsonResponse> send({
required String method,
required String requestUri,
required Map<String, AwsExceptionFn> exceptionFnMap,
bool signed = true,
Map<String, List<String>>? queryParams,
Map<String, String>? headers,
dynamic payload,
}) async {
var uri = Uri.parse('${_endpoint.url}$requestUri');
uri = uri.replace(queryParameters: {
...uri.queryParameters,
...?queryParams,
});
final rq = Request(
method,
uri,
);
rq.headers.addAll(headers ?? {});
if (payload != null) {
rq.body = json.encode(payload);
}
if (signed) {
final credentials = await _credentialsProvider?.call(client: _client);
if (credentials == null) {
throw Exception('credentials for signing request is null');
}
_requestSigner(
rq: rq,
service: _endpoint.service,
region: _endpoint.signingRegion,
credentials: credentials,
);
}
final rs = await _client.send(rq);
final body = await rs.stream.bytesToString();
if (rs.statusCode < 200 || rs.statusCode >= 300) {
throwException(rs, body, exceptionFnMap);
}
final parsedBody = body.isEmpty
? <String, dynamic>{}
: (jsonDecode(body) as Map<String, dynamic>?)!;
// TODO: replace return type with Map<String, dynamic> and discard the
// JsonResponse class. The generated code will have to adjust as well.
return JsonResponse(rs.headers, {
...parsedBody,
...rs.headers,
});
}