bodyTo<T> method

Future<T> bodyTo<T>(
  1. Converter<T, dynamic> converter, {
  2. Encoding encoding = conv.utf8,
})

Converts the body to typ T.

Implementation

Future<T> bodyTo<T>(Converter<T, dynamic> converter,
    {conv.Encoding encoding = conv.utf8}) async {
  MimeType mt = mimeType;

  Map? b;
  if (mt.isJson) {
    b = await bodyAsJsonMap(encoding: encoding);
  } else if (mt.isUrlEncodedForm) {
    b = await bodyAsUrlEncodedForm();
  } else if (mt.isFormData) {
    b = await _formDataMapToStringMap(await bodyAsFormData());
  }
  // TODO use serializer for other mimetypes

  return converter(b);
}