requestJson<S, T> method Null safety

Future<T> requestJson<S, T>(
  1. String method,
  2. String path,
  3. {int? statusCode,
  4. void fail(
    1. Response response
    )?,
  5. Map<String, String>? headers,
  6. Map<String, dynamic>? params,
  7. JSONConverter<S, T?>? convert,
  8. dynamic body,
  9. String? preview}
)

Implementation

Future<T> requestJson<S, T>(
  String method,
  String path, {
  int? statusCode,
  void Function(http.Response response)? fail,
  Map<String, String>? headers,
  Map<String, dynamic>? params,
  JSONConverter<S, T?>? convert,
  dynamic body,
  String? preview,
}) async {
  convert ??= (input) => input as T?;
  headers ??= {};

  if (preview != null) {
    headers['Accept'] = preview;
  }

  headers.putIfAbsent('Accept', () => v3ApiMimeType);

  final response = await request(
    method,
    path,
    headers: headers,
    params: params,
    body: body,
    statusCode: statusCode,
    fail: fail,
  );

  final json = jsonDecode(response.body);

  final T returnValue = convert(json)!;
  _applyExpandos(returnValue, response);
  return returnValue;
}